作者 chencheng

3

@@ -210,7 +210,8 @@ class Client extends Api @@ -210,7 +210,8 @@ class Client extends Api
210 //插入订单表 210 //插入订单表
211 $res=Db::name('verification_order')->insertGetId($data); 211 $res=Db::name('verification_order')->insertGetId($data);
212 if($res){ 212 if($res){
213 - $this->success('添加订单成功'); 213 + $res = (new \app\api\controller\v1\Wechat())->prepare_order($order_no);
  214 + $this->success('添加订单成功',$res);
214 }else{ 215 }else{
215 $this->error("添加订单失败!"); 216 $this->error("添加订单失败!");
216 } 217 }
@@ -293,10 +293,10 @@ class Wechat extends Api @@ -293,10 +293,10 @@ class Wechat extends Api
293 } 293 }
294 $userInfo = Db::name('user')->where(['id'=>$user_id])->find(); 294 $userInfo = Db::name('user')->where(['id'=>$user_id])->find();
295 295
296 - $out_trade_no = $order_no ='168532907259455'; 296 + $out_trade_no = $order_no;
297 $app = WehcatModule::getInstance()->initWechatPay(); 297 $app = WehcatModule::getInstance()->initWechatPay();
298 $result = $app->order->unify([ 298 $result = $app->order->unify([
299 - 'body' => '腾讯充值中心-QQ会员充值', 299 + 'body' => '优惠券购买',
300 'out_trade_no' => $out_trade_no, 300 'out_trade_no' => $out_trade_no,
301 'total_fee' => 1, 301 'total_fee' => 1,
302 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型 302 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
@@ -306,10 +306,10 @@ class Wechat extends Api @@ -306,10 +306,10 @@ class Wechat extends Api
306 $prepay_id = $result['prepay_id']; 306 $prepay_id = $result['prepay_id'];
307 $jssdk = $app->jssdk; 307 $jssdk = $app->jssdk;
308 $config = $jssdk->sdkConfig($prepay_id); 308 $config = $jssdk->sdkConfig($prepay_id);
309 - return $this->success('下单成功',$config); 309 + return $config;
310 310
311 }else{ 311 }else{
312 - return $this->error('下单失败',$result); 312 + return $result;
313 } 313 }
314 314
315 } 315 }
@@ -368,7 +368,7 @@ class Wechat extends Api @@ -368,7 +368,7 @@ class Wechat extends Api
368 } 368 }
369 } 369 }
370 370
371 - //查询上级 371 + //支付后,根据用户角色 处理对应的事情
372 private function getParent($pid,$verification_store_id,$order_id){ 372 private function getParent($pid,$verification_store_id,$order_id){
373 //上级身份 373 //上级身份
374 $time = time(); 374 $time = time();
@@ -377,9 +377,15 @@ class Wechat extends Api @@ -377,9 +377,15 @@ class Wechat extends Api
377 $role = Db::name('verification_staff')->where($w1)->find(); 377 $role = Db::name('verification_staff')->where($w1)->find();
378 if(in_array($role['type'],['1','3'])){ 378 if(in_array($role['type'],['1','3'])){
379 //属于代理 企业付款到佣金 379 //属于代理 企业付款到佣金
380 - return ''; 380 + $this->grant_commission($pid,$order_id);
381 }else{ 381 }else{
382 //属于普通用户 发送代金券 382 //属于普通用户 发送代金券
  383 + $this->send_voucher($pid,$verification_store_id,$order_id,$time);
  384 + }
  385 + }
  386 +
  387 + //发放代金券
  388 + public function send_voucher($pid,$verification_store_id,$order_id,$time){
383 $w1['verification_store_id'] = $verification_store_id; 389 $w1['verification_store_id'] = $verification_store_id;
384 $w1['closetime'] = ['<',$time]; 390 $w1['closetime'] = ['<',$time];
385 $coupon = Db::name('verification_coupon')->where($w1)->select(); 391 $coupon = Db::name('verification_coupon')->where($w1)->select();
@@ -389,6 +395,9 @@ class Wechat extends Api @@ -389,6 +395,9 @@ class Wechat extends Api
389 $save['verification_coupon_id'] = $v['id']; 395 $save['verification_coupon_id'] = $v['id'];
390 $save['verification_store_id'] = $v['verification_store_id']; 396 $save['verification_store_id'] = $v['verification_store_id'];
391 $save['user_id'] = $pid; 397 $save['user_id'] = $pid;
  398 + //用户是否已经领取该门店的券
  399 + $r = Db::name('verification_receive')->where($save)->find();
  400 + if(empty($r)){
392 $save['type'] = 0; 401 $save['type'] = 0;
393 $save['closetime'] = $v['closetime']; 402 $save['closetime'] = $v['closetime'];
394 $save['receive_no'] = $time.uniqid(); 403 $save['receive_no'] = $time.uniqid();
@@ -396,9 +405,22 @@ class Wechat extends Api @@ -396,9 +405,22 @@ class Wechat extends Api
396 $save['qr_code'] = $res;//二维码 405 $save['qr_code'] = $res;//二维码
397 $save['createtime'] = $time; 406 $save['createtime'] = $time;
398 $save['verification_order_id'] = $order_id; 407 $save['verification_order_id'] = $order_id;
  408 + Db::name('verification_receive')->insert($save);
399 } 409 }
400 } 410 }
401 } 411 }
402 } 412 }
403 - 413 + // 发放佣金
  414 + public function grant_commission($pid=0,$order_id=0){
  415 + $app = WehcatModule::getInstance()->initWechatPay();
  416 + $result = $app->transfer->toBalance([
  417 + 'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  418 + 'openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
  419 + 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
  420 + 're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  421 + 'amount' => 1, // 企业付款金额,单位为分
  422 + 'desc' => '理赔', // 企业付款操作说明信息。必填
  423 + ]);
  424 + dump($result);
  425 + }
404 } 426 }