作者 郭文星
@@ -202,6 +202,7 @@ class Client extends Api @@ -202,6 +202,7 @@ class Client extends Api
202 'user_id'=>$user_id, 202 'user_id'=>$user_id,
203 'createtime'=>$createtime, 203 'createtime'=>$createtime,
204 'type'=>$type, 204 'type'=>$type,
  205 + 'price'=>$activity['price'],
205 'verification_coupon_ids'=>$verification_coupon_ids, 206 'verification_coupon_ids'=>$verification_coupon_ids,
206 'verification_activity_id'=>$verification_activity_id, 207 'verification_activity_id'=>$verification_activity_id,
207 'name'=>$name, 208 'name'=>$name,
@@ -15,8 +15,8 @@ use app\api\controller\Common; @@ -15,8 +15,8 @@ use app\api\controller\Common;
15 */ 15 */
16 class Wechat extends Api 16 class Wechat extends Api
17 { 17 {
18 - protected $noNeedLogin = ["*"];  
19 - protected $noNeedRight = '*'; 18 + protected $noNeedLogin = ['*'];
  19 + protected $noNeedRight = ['*'];
20 20
21 public function _initialize() 21 public function _initialize()
22 { 22 {
@@ -286,19 +286,22 @@ class Wechat extends Api @@ -286,19 +286,22 @@ class Wechat extends Api
286 286
287 */ 287 */
288 public function prepare_order($order_no = ''){ 288 public function prepare_order($order_no = ''){
289 - $user_id = $this->auth->id;  
290 -  
291 - if(empty($user_id)){  
292 - return $this->error('预下单的用户信息错误'); 289 + if(empty($order_no)){
  290 + return $this->error('预下单信息错误');
293 } 291 }
  292 + $o_w["order_no"] = $order_no;
  293 + $order_info = Db::name('verification_order')->where($o_w)->find();
  294 + $user_id = $order_info['user_id'];
294 $userInfo = Db::name('user')->where(['id'=>$user_id])->find(); 295 $userInfo = Db::name('user')->where(['id'=>$user_id])->find();
295 -  
296 $out_trade_no = $order_no; 296 $out_trade_no = $order_no;
  297 + $o_w["order_no"] = $out_trade_no;
  298 + $order_info = Db::name('verification_order')->where($o_w)->find();
  299 + $total_fee = $order_info['price'] = 1;//测试支付1分钱
297 $app = WehcatModule::getInstance()->initWechatPay(); 300 $app = WehcatModule::getInstance()->initWechatPay();
298 $result = $app->order->unify([ 301 $result = $app->order->unify([
299 'body' => '优惠券购买', 302 'body' => '优惠券购买',
300 'out_trade_no' => $out_trade_no, 303 'out_trade_no' => $out_trade_no,
301 - 'total_fee' => 1, 304 + 'total_fee' => $total_fee,
302 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型 305 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
303 'openid' => $userInfo['openid'], 306 'openid' => $userInfo['openid'],
304 ]); 307 ]);
@@ -412,7 +415,6 @@ class Wechat extends Api @@ -412,7 +415,6 @@ class Wechat extends Api
412 } 415 }
413 // 发放佣金 416 // 发放佣金
414 public function grant_commission($pid=0,$order_id=0){ 417 public function grant_commission($pid=0,$order_id=0){
415 -  
416 try{ 418 try{
417 $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find(); 419 $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find();
418 $app = WehcatModule::getInstance()->initWechatPay(); 420 $app = WehcatModule::getInstance()->initWechatPay();
@@ -433,4 +435,32 @@ class Wechat extends Api @@ -433,4 +435,32 @@ class Wechat extends Api
433 Common::put_file_log('异常-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__); 435 Common::put_file_log('异常-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__);
434 } 436 }
435 } 437 }
  438 +
  439 +
  440 + // 发放红包
  441 + public function grant_red_packets($pid=0,$order_id=0){
  442 + try{
  443 + $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find();
  444 + $app = WehcatModule::getInstance()->initWechatPay();
  445 + $result = $app->redpack->sendNormal([
  446 +
  447 + 'mch_billno' => '168532907259455',
  448 + 'send_name' => '测试红包',
  449 + 're_openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
  450 + 'total_num' => 1, //固定为1,可不传
  451 + 'total_amount' => 100, //单位为分,不小于100
  452 + 'wishing' => '祝福语',
  453 +
  454 + 'act_name' => '测试活动',
  455 + 'remark' => '测试备注',
  456 + ]);
  457 + if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
  458 + //记录佣金表
  459 + }else{
  460 + Common::put_file_log('失败-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
  461 + }
  462 + }catch(\Exception $e){
  463 + Common::put_file_log('异常-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
  464 + }
  465 + }
436 } 466 }