|
@@ -2,11 +2,14 @@
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
+use app\admin\model\Company;
|
|
|
use app\admin\model\WechatPlan;
|
|
|
+use app\admin\model\WechatPlanRecord;
|
|
|
use app\common\controller\Api;
|
|
|
-use app\common\model\{Category, Lave as LaveModel};
|
|
|
+use app\common\model\{Category, Lave as LaveModel, User};
|
|
|
use liuniu\repositories\LaveRepository;
|
|
|
use liuniu\UtilService;
|
|
|
+use liuniu\WechatService;
|
|
|
use think\Request;
|
|
|
|
|
|
class Lave extends Api
|
|
@@ -144,7 +147,7 @@ class Lave extends Api
|
|
|
// 支付中签约
|
|
|
public function createSign(Request $request)
|
|
|
{
|
|
|
- var_dump(123);die();
|
|
|
+// var_dump(123);die();
|
|
|
$where = UtilService::postMore(
|
|
|
[
|
|
|
['cid', $this->cid],
|
|
@@ -167,6 +170,12 @@ class Lave extends Api
|
|
|
$where1 = $where;
|
|
|
unset($where1['from']);
|
|
|
$where1['order_id'] = LaveModel::getNewOrderId();
|
|
|
+ $where1['contract_code'] = WechatPlan::getNewCode();
|
|
|
+ $contract_display_account = User::where('id', $where1['user_id'])->value('nickname');
|
|
|
+ if (empty($contract_display_account)){
|
|
|
+ $this->error('用户不存在!');
|
|
|
+ }
|
|
|
+ $where1['contract_display_account']=$contract_display_account;
|
|
|
if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
|
|
|
@file_put_contents("lave.txt", json_encode($where1));
|
|
|
$order = LaveModel::create($where1);
|
|
@@ -174,18 +183,32 @@ class Lave extends Api
|
|
|
if (!$order) $this->error(LaveModel::getErrorInfo());
|
|
|
$orderId = $order['order_id'];
|
|
|
$info = compact('orderId');
|
|
|
- $order['plan_id'] = WechatPlan::where('price', $where['amount'])->value('plan_id');
|
|
|
+ $order['plan_id'] = WechatPlan::where('cid', $where['cid'])->value('plan_id');
|
|
|
if ($orderId) {
|
|
|
$orderInfo = LaveModel::where('order_id', $orderId)->find();
|
|
|
if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
|
|
|
if ($orderInfo['paid']) $this->error('支付已支付!');
|
|
|
+// 创建签约
|
|
|
+ $plan_record=[
|
|
|
+ 'plan_id'=>WechatPlan::where('price', $where['amount'])->value('plan_id'),
|
|
|
+ 'cid'=>$where['cid'],
|
|
|
+ 'uid'=>$where['user_id'],
|
|
|
+ 'price'=>$where['amount'],
|
|
|
+ 'is_signing'=>0,
|
|
|
+ 'contract_code'=>$where1['contract_code'],
|
|
|
+ 'contract_display_account'=>$where1['contract_display_account'],
|
|
|
+ 'is_open'=>$where1['is_open'],
|
|
|
+ ];
|
|
|
+ $record=WechatPlanRecord::create($plan_record);
|
|
|
+ $plan_record['spbill_create_ip']=User::where('id', $where1['user_id'])->value('loginip');
|
|
|
+ $plan_record['contract_notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $where['cid'];
|
|
|
try {
|
|
|
if ($where['from'] == 'routine') {
|
|
|
- $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId); //创建订单jspay
|
|
|
+ $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId,$plan_record); //创建订单jspay
|
|
|
} else if ($where['from'] == 'weixinh5') {
|
|
|
- $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId);
|
|
|
+ $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId,$plan_record);
|
|
|
} else {
|
|
|
- $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId);
|
|
|
+ $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId,$plan_record);
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
return $this->error($e->getMessage());
|
|
@@ -203,7 +226,7 @@ class Lave extends Api
|
|
|
*/
|
|
|
public function paySign(Request $request)
|
|
|
{
|
|
|
- var_dump(456);die();
|
|
|
+// var_dump(456);die();
|
|
|
list($uni, $paytype, $from) = UtilService::postMore([
|
|
|
['uni', ''],
|
|
|
['paytype', '0'],
|
|
@@ -234,6 +257,91 @@ class Lave extends Api
|
|
|
}
|
|
|
return $this->error('支付方式错误');
|
|
|
}
|
|
|
+ // 申请扣款
|
|
|
+ public function payPap(Request $request)
|
|
|
+ {
|
|
|
+ $list=WechatPlanRecord::where('is_signing',0)->select();
|
|
|
+ $cid=$this->cid;
|
|
|
+
|
|
|
+ $arr=[];
|
|
|
+
|
|
|
+ $arr['body']='月捐款';
|
|
|
+
|
|
|
+ foreach ($list as $k => $v){
|
|
|
+ $cid=$v['cid'];
|
|
|
+ $arr['mch_id'] =Company::where('id', $cid)->value('mch_id');
|
|
|
+ $arr['out_trade_no']=LaveModel::getNewOrderId();
|
|
|
+ $arr['total_fee'] = $v['price'];
|
|
|
+// $arr['trade_type'] = 'PAP';
|
|
|
+ $arr['contract_id'] = Company::where('id', $cid)->value('contract_id');
|
|
|
+// $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'JSAPI', [], $cid);
|
|
|
+ $rs = WechatService::papPayApply($arr['out_trade_no'], $arr['total_fee'], "lave", '月捐款', 'PAP', [], $cid,$arr['mch_id'],$arr['contract_id']);
|
|
|
+ $where1['cid']=$cid;
|
|
|
+ $where1['user_id']=$this->auth->getUserinfo()['id'];
|
|
|
+ $where1['order_name']='月捐款';
|
|
|
+ $where1['category_id']=81;
|
|
|
+ $where1['amount']=$arr['total_fee'];
|
|
|
+ $where1['name']=$this->auth->getUserinfo()['username'];
|
|
|
+ $where1['contact']='';
|
|
|
+ $where1['tel']=$this->auth->getUserinfo()['mobile'];
|
|
|
+ $where1['address']='用户未填写联系地址';
|
|
|
+ $where1['is_open']=$v['is_open'];
|
|
|
+ $where1['is_ticket']='0';
|
|
|
+ $where1['type']='0';
|
|
|
+ $where1['help_id']='0';
|
|
|
+ $order = LaveModel::create($where1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $where = UtilService::postMore(
|
|
|
+ [
|
|
|
+ ['cid', $this->cid],
|
|
|
+ ['user_id', $this->auth->getUserinfo()['id']],
|
|
|
+ ['order_name', 'order_name'],
|
|
|
+ ['category_id', 0],
|
|
|
+ ['amount', 0],
|
|
|
+ ['name', ''],
|
|
|
+ ['contact', ''],
|
|
|
+ ['tel', 0],
|
|
|
+ ['address', ''],
|
|
|
+ ['is_open', '0'],
|
|
|
+ ['is_ticket', '0'],
|
|
|
+ ['type', '0'],
|
|
|
+ ['help_id', 0],
|
|
|
+ ], $request
|
|
|
+ );
|
|
|
+ $where1 = $where;
|
|
|
+ unset($where1['from']);
|
|
|
+ $where1['order_id'] = LaveModel::getNewOrderId();
|
|
|
+ if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
|
|
|
+ @file_put_contents("lave.txt", json_encode($where1));
|
|
|
+ $order = LaveModel::create($where1);
|
|
|
+ cache('lave_' . $where['user_id'], '1', 10);
|
|
|
+ if (!$order) $this->error(LaveModel::getErrorInfo());
|
|
|
+ $orderId = $order['order_id'];
|
|
|
+ $info = compact('orderId');
|
|
|
+ $order['plan_id'] = WechatPlan::where('price', $where['amount'])->value('plan_id');
|
|
|
+ if ($orderId) {
|
|
|
+ $orderInfo = LaveModel::where('order_id', $orderId)->find();
|
|
|
+ if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
|
|
|
+ if ($orderInfo['paid']) $this->error('支付已支付!');
|
|
|
+ try {
|
|
|
+ if ($where['from'] == 'routine') {
|
|
|
+ $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId); //创建订单jspay
|
|
|
+ } else if ($where['from'] == 'weixinh5') {
|
|
|
+ $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId);
|
|
|
+ } else {
|
|
|
+ $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId);
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ $info['jsConfig'] = $jsConfig;
|
|
|
+
|
|
|
+ return $this->success('订单创建成功', $info);
|
|
|
+
|
|
|
+ } else $this->error(LaveModel::getErrorInfo());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
?>
|