作者 Cool
1 个管道 的构建 通过 耗费 0 秒

店铺申请、绑定社区功能调试

@@ -236,28 +236,35 @@ class Store extends Api @@ -236,28 +236,35 @@ class Store extends Api
236 } 236 }
237 unset($param['code']); 237 unset($param['code']);
238 $order_sn = $param['order_sn'] = get_order_sn(); 238 $order_sn = $param['order_sn'] = get_order_sn();
239 - // 获取配置  
240 - $app = new Application(ConfigService::load());  
241 - $payment = $app->payment;  
242 - // 获取支付参数  
243 - $attributes = [  
244 - 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型  
245 - 'body' => '发布招募合伙人',  
246 - 'out_trade_no' => $order_sn,  
247 - 'total_fee' => 1, // $param['money'] * 100  
248 - 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址  
249 - 'notify_url' => url('index/ajax/store_notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址  
250 - 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),  
251 - ];  
252 - $order = new Order($attributes);  
253 - $order_result = $payment->prepare($order);  
254 - if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {  
255 - $prepayId = $order_result->prepay_id;  
256 - $pay_data = $payment->configForJSSDKPayment($prepayId); 239 + // 获取入驻支付金额
  240 + $pay_data = [];
  241 + $param['money'] = $this->house_model->whereIn('id',$param['house_ids'])->sum('price');
  242 + $param['status'] = 1;
  243 + if($param['money'] > 0) {
  244 + // 获取配置
  245 + $app = new Application(ConfigService::load());
  246 + $payment = $app->payment;
  247 + // 获取支付参数
  248 + $attributes = [
  249 + 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  250 + 'body' => '发布招募合伙人',
  251 + 'out_trade_no' => $order_sn,
  252 + 'total_fee' => 1, // $param['money'] * 100
  253 + 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  254 + 'notify_url' => url('index/ajax/store_notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  255 + 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
  256 + ];
  257 + $order = new Order($attributes);
  258 + $order_result = $payment->prepare($order);
  259 + if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
  260 + $prepayId = $order_result->prepay_id;
  261 + $pay_data = $payment->configForJSSDKPayment($prepayId);
  262 + } else {
  263 + $this->error($order_result['return_msg']);
  264 + }
257 } else { 265 } else {
258 - $this->error($order_result['return_msg']); 266 + $param['status'] = 2;
259 } 267 }
260 - $param['money'] = $this->house_model->whereIn('id',$param['house_ids'])->sum('price');  
261 Db::startTrans(); 268 Db::startTrans();
262 $result = false; 269 $result = false;
263 $result_invite = true; 270 $result_invite = true;
@@ -281,7 +288,7 @@ class Store extends Api @@ -281,7 +288,7 @@ class Store extends Api
281 if(!$result || !$result_invite) { 288 if(!$result || !$result_invite) {
282 $this->error('申请提交失败'); 289 $this->error('申请提交失败');
283 } 290 }
284 - $this->success('申请提交成功',['id'=>$id,'pay_data'=>$pay_data]); 291 + $this->success('申请提交成功',['id'=>$id,'pay_status'=>$param['status'],'pay_data'=>$pay_data]);
285 } 292 }
286 293
287 /** 294 /**
@@ -964,37 +971,52 @@ class Store extends Api @@ -964,37 +971,52 @@ class Store extends Api
964 $param = (new StoreValidate())->goCheck('house_new'); 971 $param = (new StoreValidate())->goCheck('house_new');
965 $store = $this->get_store(); 972 $store = $this->get_store();
966 $order_sn = $param['order_sn'] = get_order_sn(); 973 $order_sn = $param['order_sn'] = get_order_sn();
967 - // 获取配置  
968 - $app = new Application(ConfigService::load());  
969 - $payment = $app->payment;  
970 - // 获取支付参数  
971 - $attributes = [  
972 - 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型  
973 - 'body' => '发布招募合伙人',  
974 - 'out_trade_no' => $order_sn,  
975 - 'total_fee' => 1, // $param['money'] * 100  
976 - 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址  
977 - 'notify_url' => url('index/ajax/store_order_notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址  
978 - 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),  
979 - ];  
980 - $order = new Order($attributes);  
981 - $order_result = $payment->prepare($order);  
982 - if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {  
983 - $prepayId = $order_result->prepay_id;  
984 - $pay_data = $payment->configForJSSDKPayment($prepayId); 974 + // 获取入驻支付金额
  975 + $pay_data = [];
  976 + $param['money'] = $this->house_model->whereIn('id',$param['house_ids'])->sum('price');
  977 + $param['status'] = 1;
  978 + if($param['money'] > 0) {
  979 + // 获取配置
  980 + $app = new Application(ConfigService::load());
  981 + $payment = $app->payment;
  982 + // 获取支付参数
  983 + $attributes = [
  984 + 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  985 + 'body' => '发布招募合伙人',
  986 + 'out_trade_no' => $order_sn,
  987 + 'total_fee' => 1, // $param['money'] * 100
  988 + 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  989 + 'notify_url' => url('index/ajax/store_order_notify', [], true, true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  990 + 'openid' => Db::name('third')->where('user_id', $this->auth->id)->value('openid'),
  991 + ];
  992 + $order = new Order($attributes);
  993 + $order_result = $payment->prepare($order);
  994 + if ($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
  995 + $prepayId = $order_result->prepay_id;
  996 + $pay_data = $payment->configForJSSDKPayment($prepayId);
  997 + } else {
  998 + $this->error($order_result['return_msg']);
  999 + }
985 } else { 1000 } else {
986 - $this->error($order_result['return_msg']); 1001 + $param['status'] = 2;
987 } 1002 }
988 - $param['money'] = $this->house_model->whereIn('id',$param['house_ids'])->sum('price');  
989 $model = new StoreOrder(); 1003 $model = new StoreOrder();
990 Db::startTrans(); 1004 Db::startTrans();
991 $result = false; 1005 $result = false;
992 - $result_invite = true; 1006 + $result_invite = $res_store = true;
993 try{ 1007 try{
994 $param['store_id'] = $store['id']; 1008 $param['store_id'] = $store['id'];
995 $param['user_id'] = $this->auth->id; 1009 $param['user_id'] = $this->auth->id;
996 $result = $model->add($param); 1010 $result = $model->add($param);
997 $id = $model->id; 1011 $id = $model->id;
  1012 + if($param['money'] == 0) {
  1013 + // 新增关联社区
  1014 + $update = [
  1015 + 'id' => $store['id'],
  1016 + 'house_ids' => $store['house_ids'].','.$param['house_ids']
  1017 + ];
  1018 + $res_store = Db::name('store')->where('id',$param['store_id'])->update($update);
  1019 + }
998 Db::commit(); 1020 Db::commit();
999 } catch (PDOException $e) { 1021 } catch (PDOException $e) {
1000 Db::rollback(); 1022 Db::rollback();
@@ -1003,10 +1025,10 @@ class Store extends Api @@ -1003,10 +1025,10 @@ class Store extends Api
1003 Db::rollback(); 1025 Db::rollback();
1004 $this->error($e->getMessage()); 1026 $this->error($e->getMessage());
1005 } 1027 }
1006 - if(!$result || !$result_invite) { 1028 + if(!$result || !$result_invite || !$res_store) {
1007 $this->error('提交失败'); 1029 $this->error('提交失败');
1008 } 1030 }
1009 - $this->success('提交成功',['id'=>$id,'pay_data'=>$pay_data]); 1031 + $this->success('提交成功',['id'=>$id,'pay_status'=>$param['status'],'pay_data'=>$pay_data]);
1010 } 1032 }
1011 1033
1012 /** 1034 /**