作者 chencheng

3

... ... @@ -210,7 +210,8 @@ class Client extends Api
//插入订单表
$res=Db::name('verification_order')->insertGetId($data);
if($res){
$this->success('添加订单成功');
$res = (new \app\api\controller\v1\Wechat())->prepare_order($order_no);
$this->success('添加订单成功',$res);
}else{
$this->error("添加订单失败!");
}
... ...
... ... @@ -293,10 +293,10 @@ class Wechat extends Api
}
$userInfo = Db::name('user')->where(['id'=>$user_id])->find();
$out_trade_no = $order_no ='168532907259455';
$out_trade_no = $order_no;
$app = WehcatModule::getInstance()->initWechatPay();
$result = $app->order->unify([
'body' => '腾讯充值中心-QQ会员充值',
'body' => '优惠券购买',
'out_trade_no' => $out_trade_no,
'total_fee' => 1,
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
... ... @@ -306,10 +306,10 @@ class Wechat extends Api
$prepay_id = $result['prepay_id'];
$jssdk = $app->jssdk;
$config = $jssdk->sdkConfig($prepay_id);
return $this->success('下单成功',$config);
return $config;
}else{
return $this->error('下单失败',$result);
return $result;
}
}
... ... @@ -368,7 +368,7 @@ class Wechat extends Api
}
}
//查询上级
//支付后,根据用户角色 处理对应的事情
private function getParent($pid,$verification_store_id,$order_id){
//上级身份
$time = time();
... ... @@ -377,10 +377,16 @@ class Wechat extends Api
$role = Db::name('verification_staff')->where($w1)->find();
if(in_array($role['type'],['1','3'])){
//属于代理 企业付款到佣金
return '';
$this->grant_commission($pid,$order_id);
}else{
//属于普通用户 发送代金券
$w1['verification_store_id'] = $verification_store_id;
$this->send_voucher($pid,$verification_store_id,$order_id,$time);
}
}
//发放代金券
public function send_voucher($pid,$verification_store_id,$order_id,$time){
$w1['verification_store_id'] = $verification_store_id;
$w1['closetime'] = ['<',$time];
$coupon = Db::name('verification_coupon')->where($w1)->select();
if(!empty($coupon)){
... ... @@ -389,16 +395,32 @@ class Wechat extends Api
$save['verification_coupon_id'] = $v['id'];
$save['verification_store_id'] = $v['verification_store_id'];
$save['user_id'] = $pid;
$save['type'] = 0;
$save['closetime'] = $v['closetime'];
$save['receive_no'] = $time.uniqid();
$res = (new \app\api\controller\v1\Index())->build($save['receive_no']);
$save['qr_code'] = $res;//二维码
$save['createtime'] = $time;
$save['verification_order_id'] = $order_id;
//用户是否已经领取该门店的券
$r = Db::name('verification_receive')->where($save)->find();
if(empty($r)){
$save['type'] = 0;
$save['closetime'] = $v['closetime'];
$save['receive_no'] = $time.uniqid();
$res = (new \app\api\controller\v1\Index())->build($save['receive_no']);
$save['qr_code'] = $res;//二维码
$save['createtime'] = $time;
$save['verification_order_id'] = $order_id;
Db::name('verification_receive')->insert($save);
}
}
}
}
}
// 发放佣金
public function grant_commission($pid=0,$order_id=0){
$app = WehcatModule::getInstance()->initWechatPay();
$result = $app->transfer->toBalance([
'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
'openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
'amount' => 1, // 企业付款金额,单位为分
'desc' => '理赔', // 企业付款操作说明信息。必填
]);
dump($result);
}
}
... ...