Wechat.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\ApiController;
  4. use app\api\model\taxi\UserPaymentOrder;
  5. use app\api\model\user\MotorAgent;
  6. use app\common\model\OrderPaylog;
  7. use app\common\model\TaxiUser;
  8. use app\common\model\TaxiUsersLevel;
  9. use app\common\model\Users;
  10. use EasyWeChat\Factory;
  11. use EasyWeChat\Kernel\Exceptions\Exception;
  12. use EasyWeChat\Payment\Kernel\Exceptions\InvalidSignException;
  13. use think\Db;
  14. use think\exception\DbException;
  15. use think\exception\PDOException;
  16. use think\facade\Cache;
  17. use think\facade\Log;
  18. date_default_timezone_set("Asia/Shanghai");
  19. class Wechat extends ApiController
  20. {
  21. private $config = [
  22. // 'app_id' => 'wx7a48de22423333c3',
  23. // 'secret' => '5306eb0f85490248e2f39e51dbbd6de3',
  24. 'app_id' => 'wx088555482d9bae2b',
  25. 'secret' => 'b8a3a0da52df81472af4ec1fbc4b571c',
  26. // 'response_type' => 'array',
  27. 'log' => [
  28. 'level' => 'debug',
  29. 'file' => __DIR__ . '/wechat_debug.log',
  30. ],
  31. ];
  32. private $tpl1 = [
  33. 'template_id' => 'bhkIzzwYpjjXJJ9lPdfXIsUYRrfSz52aJel1n74AA7A', // 所需下发的订阅模板id
  34. 'touser' => 'o11PJ5QDWJnIa1kPKsvvStXj243U',
  35. 'data' => [
  36. ]
  37. ];
  38. private $tpl2 = [
  39. 'template_id' => '_3OK4582YpA9s5y_6D_dwewqxqEdsd9JNrhvBFQqcrI', // 所需下发的订阅模板id
  40. 'touser' => 'o11PJ5QDWJnIa1kPKsvvStXj243U', // 接收者(用户)的 openid
  41. 'page' => '/pages/index/index', // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  42. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  43. 'thing1' => [
  44. 'value' => '拼团返现奖励金',
  45. ],
  46. 'thing2' => [
  47. 'value' => "快打开小程序,立即抢红包!",
  48. ]
  49. ]
  50. ];
  51. private $tpl3 = [
  52. 'template_id' => 'v2nNL6LKvYr0pyGsTBw5r9Zaa7lS63Hm5AjvJq-tKWc', // 所需下发的订阅模板id
  53. 'touser' => 'o11PJ5QDWJnIa1kPKsvvStXj243U',
  54. 'data' => [
  55. ]
  56. ];
  57. protected $wechat;
  58. /**
  59. *
  60. * @author 许祖兴 < zuxing.xu@lettered.cn>
  61. * @date 2020/7/1 14:46
  62. */
  63. public function initialize()
  64. {
  65. // 加载配置
  66. $wechat = sys_config('', 'wechat');
  67. //var_dump($wechat);
  68. $this->wechat = Factory::miniProgram([
  69. 'app_id' => $wechat['mini_appid'],
  70. 'secret' => $wechat['mni_secret_key'],
  71. 'response_type' => 'array',
  72. 'log' => [
  73. 'level' => 'debug',
  74. 'file' => app()->getRuntimePath() . 'log/' . date('Ym') . '/wechat_debug.log',
  75. ],
  76. ]);
  77. }
  78. /**
  79. * 获取微信session
  80. *
  81. * @return \think\response\Json
  82. * @author 许祖兴 < zuxing.xu@lettered.cn>
  83. * @date 2020/7/6 16:27
  84. *
  85. */
  86. public function getSession()
  87. {
  88. // 接收数据
  89. $param = $this->request->param();
  90. // 内置验证
  91. $valid = $this->validate($param, [
  92. 'code' => 'require'
  93. ]);
  94. // 错误
  95. if (true !== $valid) {
  96. return $this->ApiJson(-1, $valid);
  97. }
  98. $session = $this->wechat->auth->session($param['code']);
  99. if (isset($session['errcode'])) {
  100. return $this->ApiJson(-1, '获取不到用户OpenId!');
  101. }
  102. // 这里存在问题,建议修改 20210525,cache存在唯一,多个用户登录会有问题
  103. // 写入缓存
  104. Cache::set('wx_session', $session);
  105. return $this->ApiJson(0, 'OK!', $session);
  106. }
  107. /**
  108. * 前置验证
  109. *
  110. * @return array|\think\response\Json
  111. * @author 许祖兴 < zuxing.xu@lettered.cn>
  112. * @date 2020/7/8 10:55
  113. *
  114. */
  115. private function preValidData()
  116. {
  117. // 接收数据
  118. $param = $this->request->param();
  119. // 内置验证
  120. $valid = $this->validate($param, [
  121. 'encryptedData' => 'require',
  122. 'iv' => 'require',
  123. ]);
  124. // 错误
  125. if (true !== $valid) {
  126. return $this->ApiJson(-1, $valid);
  127. }
  128. return $param;
  129. }
  130. /**
  131. * 登录解密用户数据
  132. *
  133. * @return \think\response\Json
  134. * @author 许祖兴 < zuxing.xu@lettered.cn>
  135. * @date 2020/7/6 16:27
  136. *
  137. */
  138. public function login()
  139. {
  140. // 验证
  141. $param = $this->preValidData();
  142. // 读取用户session
  143. $session = Cache::get('wx_session');
  144. // app()->log(enjson([$param,$session,$parent]),'debug');
  145. // die;
  146. try {
  147. // 解密用户信息
  148. $decryptedData = $this->wechat->encryptor->decryptData($session['session_key'], $param['iv'], $param['encryptedData']);
  149. app()->log('decryptedData:' . enjson($decryptedData));
  150. // 查用户
  151. $model = model("common/Users");
  152. if (!$user = $model->where(['open_id' => $session['openid']])->find()) {
  153. // 创建新用户
  154. $model::create([
  155. 'card_id' => make_mcard_id(),
  156. 'open_id' => $session['openid'],
  157. 'avatar_url' => $decryptedData['avatarUrl'],
  158. 'nickname' => $decryptedData['nickName'],
  159. 'gender' => $decryptedData['gender']
  160. ], true);
  161. // 再查完整记录
  162. $user = $model->where(['open_id' => $session['openid']])->find();
  163. // 存在邀请码
  164. if ($param['inviteCode'] !== "" && $param['inviteCode'] !== "undefined") {
  165. // 查找上级
  166. $parent = model('common/UsersInvite')->getBy(['code' => $param['inviteCode']]);
  167. if ($parent) {
  168. // 写入关系
  169. model('common/UsersInviteRelation')->storeBy([
  170. 'form_id' => $parent['user_id'],
  171. 'invite_id' => $user['id']
  172. ]);
  173. // 推荐奖励
  174. $user_spread_property_reward = sys_config('user_spread_property_reward', 'user');
  175. model('common/Users')->changeProperty(
  176. $parent['user_id'],
  177. $user_spread_property_reward,
  178. "推荐奖励,资产【" . round($user_spread_property_reward, 3) . '】',
  179. true
  180. );
  181. // 更新上级字段
  182. $user->updateBy($user['id'], [
  183. 'parent_id' => $parent['user_id']
  184. ]);
  185. }
  186. }
  187. }
  188. // 用户状态
  189. if ($user['status'] == 0) {
  190. return $this->ApiJson(-1, '账号冻结,请联系客服');
  191. }
  192. // 登录
  193. $token = $this->auth->guard('user')->attempt($user);
  194. return $this->ApiJson(0, 'OK!', ['token' => 'Bearer ' . $token]);
  195. } catch (\Exception $e) {
  196. return $this->ApiJson(-1, $e->getMessage());
  197. }
  198. }
  199. /**
  200. * 解密手机号
  201. *
  202. * @return \think\response\Json
  203. * @author 许祖兴 < zuxing.xu@lettered.cn>
  204. * @date 2020/7/6 16:28
  205. *
  206. */
  207. public function mobile()
  208. {
  209. // 验证
  210. $param = $this->preValidData();
  211. // 读取用户session
  212. $session = Cache::get('wx_session');
  213. try {
  214. // 解密用户信息
  215. $decryptedData = $this->wechat->encryptor->decryptData($session['session_key'], $param['iv'], $param['encryptedData']);
  216. // 更新用户数据
  217. model("common/Users")->update(['mobile' => $decryptedData['phoneNumber']], ['open_id' => $session['openid']]);
  218. return $this->ApiJson(0, 'OK!', $decryptedData);
  219. } catch (\Exception $e) {
  220. return $this->ApiJson(-1, $e->getMessage());
  221. }
  222. }
  223. /**
  224. * 统一支付
  225. *
  226. * @return \think\response\Json
  227. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  228. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  229. * @throws \GuzzleHttp\Exception\GuzzleException
  230. * @throws \Lettered\Support\Exceptions\FailedException
  231. * @author 许祖兴 < zuxing.xu@lettered.cn>
  232. * @date 2020/7/7 10:27
  233. *
  234. */
  235. public function payment()
  236. {
  237. // 查
  238. $param = $this->request->param();
  239. $param['payType'] = input('payType', 'wechat');
  240. // 数据校验
  241. $valid = $this->validate($param, [
  242. 'trade_no|支付单号' => 'require',
  243. 'payType|支付方式' => 'require'
  244. ]);
  245. // 错误
  246. if (true !== $valid) {
  247. return $this->ApiJson(-1, $valid);
  248. }
  249. // 数据检查
  250. $paylog = model('common/OrderPaylog')->getBy(['out_trade_no' => $param['trade_no']]);
  251. if (!$paylog) {
  252. return $this->ApiJson(-1, '本次交易不存在');
  253. }
  254. if ($paylog['is_pay'] == 1) {
  255. return $this->ApiJson(-1, '本次交易已处理,请勿重复操作');
  256. }
  257. // 选中支付方式
  258. switch ($param['payType']) {
  259. case 'alipay':
  260. case 'wechat':
  261. return $this->thirdPayment($param['payType'], $paylog);
  262. break;
  263. case 'property':
  264. default:
  265. // 默认余额支付
  266. // 1. 支付订单
  267. // 2. 扣减余额
  268. return $this->buyOnUserSelf($param['payType'], $paylog);
  269. break;
  270. }
  271. }
  272. /***
  273. *
  274. * @return \think\response\Json
  275. * @throws \Lettered\Support\Exceptions\FailedException
  276. * @author 许祖兴 < zuxing.xu@lettered.cn>
  277. * @date 2020/7/15 11:00
  278. *
  279. */
  280. public function repay()
  281. {
  282. $param = $this->request->param();
  283. // 数据校验
  284. $valid = $this->validate($param, [
  285. 'order_id|订单号' => 'require',
  286. ]);
  287. // 错误
  288. if (true !== $valid) {
  289. return $this->ApiJson(-1, $valid);
  290. }
  291. // 订单信息
  292. $order = model('common/GoodsOrder')
  293. ->getBy(['id' => $param['order_id'], 'user_id' => $this->auth->user()['id']]);
  294. // 数据检查
  295. $paylog = model('common/OrderPaylog')->getBy(['order_idx' => $param['order_id'], 'ascription' => 'goods']);
  296. if (!$paylog) {
  297. return $this->ApiJson(-1, '本次交易不存在');
  298. }
  299. if ($paylog['is_pay'] == 1) {
  300. return $this->ApiJson(-1, '本次交易已处理,请勿重复操作');
  301. }
  302. // 是否有过记录
  303. if (!$paylog) {
  304. // 二次创建子支付
  305. $trade_no = get_order_no();
  306. model('common/OrderPaylog')->storeBy([
  307. 'order_idx' => $param['order_id'],
  308. 'out_trade_no' => $trade_no,
  309. 'total_price' => $order['total_price'],
  310. 'ascription' => 'goods' // 归属订单
  311. ]);
  312. return $this->ApiJson(0, '获取支付信息成功', $trade_no);
  313. }
  314. // 再次支付
  315. return $this->ApiJson(0, '获取支付信息成功', $paylog['out_trade_no']);
  316. }
  317. public function refund()
  318. {
  319. // 查
  320. $param = $this->request->param();
  321. $param['payType'] = input('payType', 'wechat');
  322. // 数据校验
  323. $valid = $this->validate($param, [
  324. 'trade_no|支付单号' => 'require',
  325. 'payType|支付方式' => 'require'
  326. ]);
  327. // 错误
  328. if (true !== $valid) {
  329. return $this->ApiJson(-1, $valid);
  330. }
  331. // 数据检查
  332. $paylog = model('common/OrderPaylog')->getBy(['out_trade_no' => $param['trade_no']]);
  333. if (!$paylog) {
  334. return $this->ApiJson(-1, '本次交易不存在');
  335. }
  336. if ($paylog['is_pay'] != 1) {
  337. return $this->ApiJson(-1, '本次交易未支付');
  338. }
  339. return $this->thirdRefund('wechat', $paylog);
  340. }
  341. /**
  342. * 支付通知
  343. *
  344. * @throws \EasyWeChat\Kernel\Exceptions\Exception
  345. * @author 许祖兴 < zuxing.xu@lettered.cn>
  346. * @date 2020/7/7 9:56
  347. *
  348. */
  349. public function paymentNotify()
  350. {
  351. // 加载配置
  352. $wechat = sys_config('', 'wechat');
  353. // 发起支付
  354. $config = [
  355. 'app_id' => $wechat['mini_appid'],
  356. 'mch_id' => $wechat['pay_mch_id'],
  357. 'key' => $wechat['pay_secret_key'],
  358. ];
  359. app()->log("微信异步:" . enjson($config), 'debug');
  360. // 创建应用实例
  361. $payment = Factory::payment($config);
  362. Db::startTrans();
  363. try {
  364. // 响应处理
  365. $response = $payment->handlePaidNotify(function ($message, $fail) {
  366. app()->log("微信异步:" . enjson($message), 'debug');
  367. // 获取支付订单
  368. $order = model('common/OrderPaylog')->where(['out_trade_no' => $message['out_trade_no']])->lock(true)->find();
  369. // 订单状态
  370. if (!$order || $order->is_pay == 1) {
  371. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  372. }
  373. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  374. Log::debug(enjson($message));
  375. // 支付成功
  376. $pay_price = sprintf("%.2f", round($message['total_fee'] / 100, 2));
  377. // 1. 支付订单状态is_pay =1
  378. model('common/OrderPaylog')->updateBy($order['id'], [
  379. 'pay_price' => $pay_price,
  380. 'is_pay' => 1,
  381. ]);
  382. // TODO 下面的写法我自己都看累,应该提出对应方法好处理写 =_=
  383. $thing5 = '感谢您的支持,我们将致力于更好的服务!';
  384. // 2. 对归属订单状态处理
  385. foreach (str2arr($order['order_idx']) as $orderId) {
  386. // 所属订单
  387. //TODO 等待优化
  388. $goodsOrder = [];
  389. // 模板消息标题
  390. $tplTitle = "";
  391. switch ($order['ascription']) {
  392. // 田地订单
  393. case "farmland":
  394. $tplTitle = "人人接 - 田地服务";
  395. $goodsOrder = model('common/FarmlandOrder')->getBy(['id' => $orderId]);
  396. model('common/FarmlandOrder')->updateBy($orderId, ['status' => 2, 'pay_type' => 'wechat']);
  397. // todo 停止本次招标
  398. model('common/FarmlandBlock')->updateBy($goodsOrder['block_id'], [
  399. 'status' => 2 // 1 可用 2 服务中
  400. ]);
  401. push_socket_data('farmland', [
  402. 'id' => $orderId,
  403. 'msg' => '有新的农田订单等待处理,点击前往!'
  404. ]);
  405. break;
  406. // 摩的订单
  407. case "motor":
  408. $tplTitle = "人人接 - 摩的服务";
  409. $goodsOrder = model('common/TaxiOrder')->getBy(['id' => $orderId]);
  410. model('common/TaxiOrder')->updateBy($orderId, ['status' => 2]);
  411. push_socket_data('motor', [
  412. 'id' => $orderId,
  413. 'msg' => '有新的摩的订单等待处理,点击前往!'
  414. ]);
  415. // 订阅消息
  416. $thing5 = '电话请保持通畅,师傅正在赶往路上,请稍候';
  417. // 订单结算给摩的代理
  418. //model('\app\api\model\taxi\Award')->send($goodsOrder);
  419. break;
  420. // 技能订单
  421. case "skill":
  422. $tplTitle = "人人接 - 技能服务";
  423. $goodsOrder = model('common/SkillOrder')->getBy(['id' => $orderId]);
  424. model('common/SkillOrder')->updateBy($orderId, ['status' => 2]);
  425. push_socket_data('skill', [
  426. 'id' => $orderId,
  427. 'msg' => '有新的技能订单等待处理,点击前往!'
  428. ]);
  429. break;
  430. // 配送订单
  431. case "mission":
  432. $tplTitle = "人人接 - 配送服务";
  433. $goodsOrder = model('common/MissionOrder')->getBy(['id' => $orderId]);
  434. model('common/MissionOrder')->updateBy($orderId, ['status' => 2]);
  435. push_socket_data('mission', [
  436. 'id' => $orderId,
  437. 'msg' => '有新的配送订单等待处理,点击前往!'
  438. ]);
  439. break;
  440. // 救援订单
  441. case "rescue":
  442. $tplTitle = "人人接 - 救援服务";
  443. $goodsOrder = model('common/RescueOrder')->getBy(['id' => $orderId]);
  444. model('common/RescueOrder')->updateBy($orderId, ['status' => 2]);
  445. push_socket_data('rescue', [
  446. 'id' => $orderId,
  447. 'msg' => '有新的救援订单等待处理,点击前往!'
  448. ]);
  449. break;
  450. // 商品订单
  451. case "goods":
  452. $tplTitle = "人人接 - 商品购买";
  453. // 产品订单
  454. $goodsOrder = model('common/GoodsOrder')->where(['id' => $orderId])->lock(true)->find();
  455. // 已经支付过了
  456. if ($goodsOrder['status'] !== 1) {
  457. return $fail('已经支付过了');
  458. }
  459. // 获取当前支付订单是否为拼团
  460. // todo
  461. if ($goodsOrder && $goodsOrder['is_pin']) {
  462. $this->dealWithPinOrder($pay_price, $goodsOrder);
  463. } else {
  464. // 0: 已关闭 1:待支付, 2:待发货,3:待收货 , 4: 已完成 , 5: 待开团 , 6: 未中团
  465. // 数据更新
  466. model('common/GoodsOrder')->updateBy($orderId, [
  467. 'pay_price' => $pay_price,
  468. 'paid_at' => time(),
  469. 'status' => 2
  470. ]);
  471. }
  472. $thing5 = '顾客您好您的订单已出库小哥预计十分钟送达';
  473. push_socket_data('goods', [
  474. 'id' => $orderId,
  475. 'msg' => '有新的商品订单等待处理,点击前往!'
  476. ]);
  477. break;
  478. // 司机升级订单
  479. case "level":
  480. $tplTitle = "人人接 - 司机付费升级";
  481. // 订单
  482. $goodsOrder = UserPaymentOrder::where(['id' => $orderId])->find();
  483. if (empty($goodsOrder)) {
  484. return $fail('订单不存在');
  485. }
  486. // 已经支付过了
  487. if ($goodsOrder['status'] !== 1) {
  488. return $fail('已经支付过了');
  489. }
  490. $levelData = TaxiUsersLevel::where(['id' => $goodsOrder['source_id']])->find();
  491. if (empty($levelData)) {
  492. return $fail('升级参数错误');
  493. }
  494. // 数据更新
  495. if (!UserPaymentOrder::where(['id' => $orderId])->update([
  496. 'pay_at' => time(),
  497. 'status' => 2
  498. ])) {
  499. return $fail('升级订单处理失败');
  500. }
  501. if (!TaxiUser::where(['user_id' => $goodsOrder['user_id']])->update(['level' => $levelData['level']])) {
  502. return $fail('司机等级更新失败');
  503. }
  504. $user = model('common/Users')->getBy(['id' => $goodsOrder['user_id']]);
  505. if (!Users::where(['id'=>$goodsOrder['user_id']])->update(['taxi_property'=> $goodsOrder['price']+$user['taxi_property']])) {
  506. return $fail('司机资产更新失败');
  507. }
  508. $thing5 = '尊敬的用户您好,您的升级订单已经支付成功!';
  509. break;
  510. case "motor_agent":
  511. $UserPaymentOrder = new UserPaymentOrder();
  512. $goodsOrder = $UserPaymentOrder->with('agent,user')
  513. ->field('id,user_id,order_no,status')
  514. ->find($orderId);
  515. // 更新订单信息
  516. $goodsOrder->status = 2;
  517. $goodsOrder->save();
  518. // 更新摩的代理
  519. $goodsOrder->agent->status = 40;
  520. $goodsOrder->agent->save();
  521. // 更新用户信息
  522. $goodsOrder->user->is_motor_agent = 2;
  523. $goodsOrder->user->save();
  524. break;
  525. case "motor_driver":
  526. $UserPaymentOrder = new UserPaymentOrder();
  527. $goodsOrder = $UserPaymentOrder->with('driver')
  528. ->field('id,user_id,order_no,status')
  529. ->find($orderId);
  530. // 更新订单信息
  531. $goodsOrder->status = 2;
  532. $goodsOrder->save();
  533. // 更新摩的代理
  534. $goodsOrder->driver->status = 1;
  535. $goodsOrder->driver->save();
  536. }
  537. // 获取用户
  538. $user = model('common/Users')->getBy(['id' => $goodsOrder['user_id']]);
  539. // 用户消费金额处理
  540. // 写入本次消费后总金额
  541. $user_consume_total = $user['consume'] + $pay_price;
  542. model('common/Users')->updateBy($goodsOrder['user_id'], [
  543. 'consume' => sprintf('%.2f', $user_consume_total)
  544. ]);
  545. // 3.查找用户消费获得资产奖励
  546. if ($order['ascription'] == 'goods') {
  547. // 消费总额包含 商品、接单、技能、摩的
  548. // 获取资产设置
  549. $user_property_reward = sys_config('user_property_reward', 'user');
  550. if ($user_property_reward != '') {
  551. foreach (str2arr($user_property_reward, ',') as $key => $reward) {
  552. list($select, $amount) = str2arr($reward, ":");
  553. if ($amount == 0) continue;
  554. // 当前总消费达到奖励
  555. if ($user_consume_total >= $select && $key == $user['property_count']) {
  556. //TODO 达到消费 -- 反奖励
  557. model('common/Users')->changeProperty(
  558. $goodsOrder['user_id'],
  559. sprintf("%.2f", round($amount, 2)),
  560. "消费满 {$select},平台奖励资产【" . sprintf("%.2f", round($amount, 2)) . '】',
  561. true
  562. );
  563. // 增加领取次数
  564. model('common/Users')->where(['id' => $goodsOrder['user_id']])
  565. ->setInc('property_count');
  566. }
  567. }
  568. }
  569. }
  570. // 模板消息
  571. $this->tpl1['touser'] = $user['open_id'];
  572. $this->tpl1['data'] = [
  573. 'character_string1' => [
  574. 'value' => $goodsOrder['order_no'],
  575. ],
  576. 'thing3' => [
  577. 'value' => $tplTitle,
  578. ],
  579. 'amount4' => [
  580. 'value' => $pay_price,
  581. ],
  582. 'date2' => [
  583. 'value' => date("Y/m/d H:i:s"),
  584. ],
  585. 'thing7' => [
  586. 'value' => $thing5,
  587. ]
  588. ];
  589. $this->wechat->subscribe_message->send($this->tpl1);
  590. }
  591. return true;
  592. } else {
  593. return $fail('支付失败,请稍后再通知我');
  594. }
  595. });
  596. Db::commit();
  597. return $response->send(); // Laravel 里请使用:return $response;
  598. } catch (Exception $e) {
  599. app()->log('支付错误:' . $e->getMessage(),'pay');
  600. Db::rollback();
  601. return $this->ApiJson(-1, "支付返回时错误!" . $e->getMessage());
  602. }
  603. }
  604. /**
  605. * 获取小程序分享码
  606. *
  607. * @return \think\response\Json
  608. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  609. * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
  610. * @throws \Lettered\Support\Exceptions\FailedException
  611. * @throws \think\db\exception\DataNotFoundException
  612. * @throws \think\db\exception\ModelNotFoundException
  613. * @throws \think\exception\DbException
  614. * @author 许祖兴 < zuxing.xu@lettered.cn>
  615. * @date 2020/6/26 18:11
  616. *
  617. */
  618. public function getShareSpread()
  619. {
  620. // 获取用户信息
  621. $user = $this->auth->user();
  622. // 获取邀请信息
  623. $spread = model('common/UsersInvite')
  624. ->where(['user_id' => $user['id']])->find();
  625. // 存在性判断
  626. if (!$spread) {
  627. // 邀请码就选择用户ID
  628. $response = $this->wechat->app_code->getUnlimit('spd=' . $user['card_id'], [
  629. // 'scene' => [
  630. // 'spd' => $user['card_id']
  631. // ],
  632. 'page' => 'pages/index/index',
  633. 'width' => 600,
  634. 'line_color' => [
  635. 'r' => 236,
  636. 'g' => 108,
  637. 'b' => 68,
  638. ]
  639. ]);
  640. // 检查
  641. if (is_array($response) && $response['errcode'] == '41030') {
  642. return $this->ApiJson(-1, '当前体验版无法生成二维码,请上线后重试~');
  643. }
  644. // 保存二维码
  645. if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
  646. $filename = $response->saveAs($this->app->getRootPath() . 'public/uploads/spread', md5(time()) . '.png');
  647. $qrImg = get_annex_url('/spread/' . $filename);
  648. //TODO 二维码写入数据库
  649. model('common/UsersInvite')->storeBy([
  650. 'user_id' => $user['id'],
  651. 'code' => $user['card_id'],
  652. 'qr_img' => $qrImg
  653. ]);
  654. return $this->ApiJson(0, 'OK!', [
  655. 'inviteCode' => $user['card_id'],
  656. 'qrcodeImg' => $qrImg
  657. ]);
  658. }
  659. return $this->ApiJson(-1, '生成邀请失败,请稍后重试~');
  660. }
  661. return $this->ApiJson(0, 'OK!', [
  662. 'inviteCode' => $spread['code'],
  663. 'qrcodeImg' => $spread['qr_img']
  664. ]);
  665. }
  666. private function thirdPayment($channel, $paylog)
  667. {
  668. // 目前就微信支付
  669. // 加载配置
  670. $wechat = sys_config('', $channel);
  671. // 发起支付
  672. $config = [
  673. // 前面的appid什么的也得保留哦
  674. 'app_id' => $wechat['mini_appid'],
  675. 'mch_id' => $wechat['pay_mch_id'],
  676. 'key' => $wechat['pay_secret_key'],
  677. // 'notify_url' => 'https://api.gxrrj.cn/api/v1/wechat/notify',
  678. 'notify_url' => site_url() . '/api/v1/wechat/notify',
  679. // 'notify_url' => 'http://ncnjmz.natappfree.cc/api/v1/wechat/notify',
  680. // 'sandbox' => true
  681. ];
  682. app()->log(json_encode($config, 256),'wechat');
  683. // 创建应用实例
  684. $payment = Factory::payment($config);
  685. $jssdk = $payment->jssdk;
  686. // 服务名称
  687. $serve = "";
  688. switch ($paylog['ascription']) {
  689. case 'farmland':
  690. $serve = "田地服务";
  691. break;
  692. case 'motor':
  693. $serve = "摩的服务";
  694. break;
  695. case 'skill':
  696. $serve = "技能服务";
  697. break;
  698. case 'mission':
  699. $serve = "配送服务";
  700. break;
  701. case 'goods':
  702. $serve = "商品购买";
  703. break;
  704. case 'level':
  705. $serve = "司机付费升级";
  706. break;
  707. }
  708. // 统一下单
  709. $result = $payment->order->unify([
  710. 'attach' => $paylog['ascription'], // 附加数据,区分订单所属
  711. 'body' => '人人接 - ' . $serve,
  712. 'out_trade_no' => $paylog['out_trade_no'],
  713. 'total_fee' => round($paylog['total_price'] * 100),
  714. 'trade_type' => 'JSAPI',
  715. 'openid' => $this->auth->user()['open_id']
  716. ]);
  717. app()->log('提交支付' . enjson($result), 'debug');
  718. if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
  719. return $this->ApiJson(0, '', $jssdk->sdkConfig($result['prepay_id']));
  720. }
  721. return $this->ApiJson(-1, isset($result['return_msg']) ? $result['return_msg'] : '支付异常,请稍后重试...');
  722. }
  723. private function thirdRefund($channel, $paylog)
  724. {
  725. // 1.查找对应是否有退款订单
  726. // 2.创建退款单记录
  727. // 3.请求微信退款
  728. // 参数分别为:微信订单号、商户退款单号、订单金额、退款金额、其他参数
  729. //$app->refund->byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $config = []);
  730. // Example:
  731. $result = $app->refund->byTransactionId($paylog['out_trade_no'], 'refund-no-xxx', 10000, 10000, [
  732. // 可在此处传入其他参数,详细参数见微信支付文档
  733. 'refund_desc' => '商品已售完',
  734. ]);
  735. }
  736. /**
  737. * 余额支付
  738. *
  739. * @param $payType
  740. * @param $paylog
  741. * @return \think\response\Json
  742. * @throws \Lettered\Support\Exceptions\FailedException
  743. * @throws \think\Exception
  744. * @throws \think\db\exception\DataNotFoundException
  745. * @throws \think\db\exception\ModelNotFoundException
  746. * @throws \think\exception\DbException
  747. * @throws \think\exception\PDOException
  748. * @author 许祖兴 < zuxing.xu@lettered.cn>
  749. * @date 2020/8/6 16:39
  750. *
  751. */
  752. private function buyOnUserSelf($payType = 'balance', $paylog)
  753. {
  754. // 检查用户余额
  755. $user = $this->auth->user();
  756. if ($user[$payType] < $paylog['total_price']) {
  757. return $this->ApiJson(-1, '支付失败,账户余额不足!');
  758. }
  759. // 支付金额
  760. $pay_price = sprintf("%.2f", round($paylog['total_price'], 2));
  761. Db::startTrans();
  762. try {
  763. // 支付成功 支付订单状态is_pay =1
  764. model('common/OrderPaylog')->updateBy($paylog['id'], [
  765. 'pay_price' => $pay_price,
  766. 'pay_type' => $payType, // 默认支付方式
  767. 'is_pay' => 1,
  768. ]);
  769. $orderId = $paylog['order_idx'];
  770. // 模板消息标题
  771. $tplTitle = "";
  772. $thing7 = '感谢您的支持,我们将致力于更好的服务!';
  773. $goodsOrder = 1;
  774. switch ($paylog['ascription']) {
  775. // 田地订单
  776. case "farmland":
  777. $goodsOrder = model('common/FarmlandOrder')->getBy(['id' => $orderId]);
  778. $tplTitle = "人人接 - 田地服务";
  779. model('common/FarmlandOrder')->updateBy($orderId, ['status' => 2, 'pay_type' => $payType]);
  780. // todo 停止本次招标
  781. model('common/FarmlandBlock')->updateBy($goodsOrder['block_id'], [
  782. 'status' => 2 // 1 可用 2 服务中
  783. ]);
  784. push_socket_data('farmland', [
  785. 'id' => $orderId,
  786. 'msg' => '有新的农田订单等待处理,点击前往!'
  787. ]);
  788. break;
  789. // 摩的订单
  790. case "motor":
  791. $goodsOrder = model('common/TaxiOrder')->getBy(['id' => $orderId]);
  792. $tplTitle = "人人接 - 摩的服务";
  793. model('common/TaxiOrder')->updateBy($orderId, ['status' => 2]);
  794. push_socket_data('motor', [
  795. 'id' => $orderId,
  796. 'msg' => '有新的摩的订单等待处理,点击前往!'
  797. ]);
  798. // 订阅消息
  799. // $thing7 = '电话请保持通畅,师傅正在赶往路上,请稍候';
  800. // 订单结算给摩的代理
  801. //model('\app\api\model\taxi\Award')->send($goodsOrder);
  802. break;
  803. // 技能订单
  804. case "skill":
  805. $tplTitle = "人人接 - 技能服务";
  806. $goodsOrder = model('common/SkillOrder')->getBy(['id' => $orderId]);
  807. model('common/SkillOrder')->updateBy($orderId, ['status' => 2]);
  808. push_socket_data('skill', [
  809. 'id' => $orderId,
  810. 'msg' => '有新的技能订单等待处理,点击前往!'
  811. ]);
  812. break;
  813. // 配送订单
  814. case "mission":
  815. $tplTitle = "人人接 - 配送服务";
  816. $goodsOrder = model('common/MissionOrder')->getBy(['id' => $orderId]);
  817. model('common/MissionOrder')->updateBy($orderId, ['status' => 2]);
  818. push_socket_data('mission', [
  819. 'id' => $orderId,
  820. 'msg' => '有新的配送订单等待处理,点击前往!'
  821. ]);
  822. break;
  823. // 救援订单
  824. case "rescue":
  825. $tplTitle = "人人接 - 救援服务";
  826. $goodsOrder = model('common/RescueOrder')->getBy(['id' => $orderId]);
  827. model('common/RescueOrder')->updateBy($orderId, ['status' => 2]);
  828. push_socket_data('rescue', [
  829. 'id' => $orderId,
  830. 'msg' => '有新的救援订单等待处理,点击前往!'
  831. ]);
  832. break;
  833. // 商品订单
  834. case "goods":
  835. // 获取订单产品
  836. $goods = model('common/GoodsOrderDetail')->where(['order_id' => $paylog['order_idx']])->find();
  837. $tplTitle = $goods['title'];
  838. // 产品订单
  839. $goodsOrder = model('common/GoodsOrder')->where(['id' => $paylog['order_idx']])->lock(true)->find();
  840. // 获取当前支付订单是否为拼团
  841. if ($goodsOrder && $goodsOrder['is_pin']) {
  842. $this->dealWithPinOrder($pay_price, $goodsOrder);
  843. } else {
  844. // 0: 已关闭 1:待支付, 2:待发货,3:待收货 , 4: 已完成 , 5: 待开团 , 6: 未中团
  845. // 数据更新
  846. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  847. 'pay_price' => $pay_price,
  848. 'paid_at' => time(),
  849. 'status' => 2
  850. ]);
  851. }
  852. push_socket_data('goods', [
  853. 'id' => $goodsOrder['id'],
  854. 'msg' => '有新的商品订单等待处理,点击前往!'
  855. ]);
  856. break;
  857. }
  858. //$user = model('common/Users')->getBy(['id' => $goodsOrder['user_id']]);
  859. // 扣减账户余额
  860. if ($payType == 'balance') {
  861. model('common/Users')->changeBalance(
  862. $user['id'],
  863. $pay_price,
  864. "支付成功,支付金额【" . $pay_price . "】"
  865. );
  866. } else if ($payType == 'property') {
  867. model('common/Users')->changeProperty(
  868. $user['id'],
  869. $pay_price,
  870. "消费成功,消费资产【{$pay_price}】"
  871. );
  872. }
  873. // 查找用户消费获得资产奖励 - 资产消费无法获得资产
  874. if ($paylog['ascription'] == 'goods' && $payType != 'property') {
  875. // 用户消费金额处理
  876. // 写入本次消费后总金额
  877. $user_consume_total = $user['consume'] + $pay_price;
  878. model('common/Users')->updateBy($user['id'], [
  879. 'consume' => sprintf('%.2f', $user_consume_total)
  880. ]);
  881. // 消费总额包含 商品、接单、技能、摩的
  882. // 获取资产设置
  883. $user_property_reward = sys_config('user_property_reward', 'user');
  884. if ($user_property_reward != '') {
  885. foreach (str2arr($user_property_reward, ',') as $key => $reward) {
  886. list($select, $amount) = str2arr($reward, ":");
  887. if ($amount == 0) continue;
  888. // 当前总消费达到奖励
  889. if ($user_consume_total >= $select && $key == $user['property_count']) {
  890. //TODO 达到消费 -- 反奖励
  891. model('common/Users')->changeProperty(
  892. $goodsOrder['user_id'],
  893. sprintf("%.2f", round($amount, 2)),
  894. "消费满 {$select},平台奖励资产【" . sprintf("%.2f", round($amount, 2)) . '】',
  895. true
  896. );
  897. // 增加领取次数
  898. model('common/Users')->where(['id' => $goodsOrder['user_id']])
  899. ->setInc('property_count');
  900. }
  901. }
  902. }
  903. }
  904. // 模板消息
  905. $this->tpl1['touser'] = $user['open_id'];
  906. $this->tpl1['data'] = [
  907. 'character_string1' => [
  908. 'value' => $goodsOrder['order_no'],
  909. ],
  910. 'thing3' => [
  911. 'value' => $tplTitle,
  912. ],
  913. 'amount4' => [
  914. 'value' => $pay_price,
  915. ],
  916. 'date2' => [
  917. 'value' => date("Y/m/d H:i:s"),
  918. ],
  919. 'thing7' => [
  920. 'value' => $thing7,
  921. ]
  922. ];
  923. // $this->wechat->subscribe_message->send($this->tpl1);
  924. Db::commit();
  925. return $this->ApiJson(0, '支付成功');
  926. } catch (\Exception $e) {
  927. Log::error('支付错误:' . $e->getMessage() . $e->getTraceAsString());
  928. Db::rollback();
  929. return $this->ApiJson(-1, $e->getMessage());
  930. }
  931. }
  932. private function dealWithPinOrder($pay_price, $goodsOrder)
  933. {
  934. // 拼单详情
  935. $gorder_detail = model('common/GoodsOrderDetail')->getBy(['order_id' => $goodsOrder['id']]);
  936. // 查拼单产品
  937. $goods = model('common/Goods')->where(['id' => $gorder_detail['goods_id']])->lock(true)->find();
  938. // 支付成功 -- 0 为创建拼团
  939. if ($goodsOrder['group_id'] == 0) {
  940. $joinId = model('common/GoodsOrderGroup')->storeBy([
  941. 'user_id' => $goodsOrder['user_id'],
  942. 'goods_id' => $goods['id'],
  943. 'pin_sum' => $goods['pin_sum'],
  944. 'pin_number' => $goods['pin_number'],
  945. // 超时时间
  946. 'expired_at' => time() + (sys_config('pin_expired_at', 'store') * 3600) // 24 * 3600
  947. ]);
  948. // 数据更新
  949. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  950. 'group_id' => $joinId, //创建的时候追加拼团id
  951. 'pay_price' => $pay_price,
  952. 'paid_at' => time(),
  953. 'status' => 5
  954. ]);
  955. } else { // 参加拼团 -- 增加人数
  956. $groupOrder = model('common/GoodsOrderGroup')->where(['id' => $goodsOrder['group_id']])->lock(true)->find();
  957. // 1. 是否已经拼满了,或者已经拼单成功了 -- 拼单满了就直接拼单失败,直接返回金额到余额,关闭订单开启限时红白奖励
  958. if (($groupOrder['pin_sum'] == $groupOrder['now_number']) || $groupOrder['status'] == 1) {
  959. // 关闭我的订单 -- 这里应该直接关闭订单直接返款,没有红包
  960. // 先返款
  961. model('common/Users')->changeBalance(
  962. $goodsOrder['user_id'],
  963. $pay_price,
  964. "参团失败,退还支付金额【" . $pay_price . '】',
  965. true
  966. );
  967. // 单产品SKU库存回增
  968. model('common/GoodsSku')
  969. ->where(['param' => enjson(str2arr($gorder_detail['spec']))])
  970. ->setInc('stock', $gorder_detail['count']);
  971. // 产品总库存更新
  972. model('common/Goods')
  973. ->where(['id' => $gorder_detail['goods_id']])
  974. ->setInc('stock', $gorder_detail['count']);
  975. // 销量减
  976. model('common/Goods')
  977. ->where(['id' => $gorder_detail['goods_id']])
  978. ->setDec('sell_count', $gorder_detail['count']);
  979. // 再更新 -- 关闭订单
  980. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  981. 'pay_price' => $pay_price,
  982. 'paid_at' => time(),
  983. 'status' => 0
  984. ]);
  985. } else {
  986. // pin_sum 拼团人数
  987. // pin_number 获得人数
  988. // now_number 当前人数
  989. // 2. 加入拼单成功,检查我是不是最后一个,最后一个直接开团,获得者从随机获得
  990. $gog = model('common/GoodsOrderGroup')->where(['id' => $goodsOrder['group_id']]);
  991. $gog->setInc('now_number', $gorder_detail['count']);
  992. // 当前人数检查 -- 达到拼团人数--开团
  993. if ($groupOrder['pin_sum'] == $gog->value("now_number")) {
  994. // 当前拼单成团 - 进行逻辑发放
  995. // 查找当前拼团下的所有订单
  996. $cgo = model('common/GoodsOrder')
  997. ->where(['group_id' => $groupOrder['id']])
  998. ->select();
  999. // 利润 count * ( total_price - instock )
  1000. // 总利润
  1001. $cgo_total = 0;
  1002. // 子单
  1003. foreach ($cgo as $item) {
  1004. // 子单明细
  1005. $its = model('common/GoodsOrderDetail')->where(['order_id' => $item['id']])->select();
  1006. foreach ($its as $itsv) {
  1007. // 产品
  1008. $goin = model('common/GoodsSku')->where(['goods_id' => $itsv['goods_id'], 'param' => enjson(str2arr($itsv['spec'], ','))])->value('instock_price');
  1009. $cgo_total += sprintf("%.2f", round($itsv['total_price'] - $goin, 2));
  1010. }
  1011. }
  1012. // todo 返现生成如果是按百分比和整数混合
  1013. $pin_rebate_amount = sys_config('pin_rebate_amount', 'store');
  1014. $pin_rebate_expired_at = sys_config('pin_rebate_expired_at', 'store');
  1015. // 20200730 客户说按利润比得数据
  1016. // 利润 * 比例 = 要发放的钱
  1017. $rebate = sprintf("%.2f", round($cgo_total * (float)$pin_rebate_amount / 100, 2));
  1018. $num = count($cgo);// 分成10个红包,支持10人随机领取
  1019. $min = 0.01 * $rebate;//每个人最少能收到0.01元
  1020. $rArr = [];
  1021. for ($i = 1; $i < $num; $i++) {
  1022. $safe_total = ($rebate - ($num - $i) * $min) / ($num - $i);//随机安全上限
  1023. $money = mt_rand($min * 100, $safe_total * 100) / 100;
  1024. $rebate -= $money;
  1025. $rArr[$i] = $money;
  1026. }
  1027. $rArr[$num] = $rebate;
  1028. //TODO 暂时脑子瓦特,想不到什么好办法
  1029. // 0: 已关闭 1:待支付, 2:待发货,3:待收货 , 4: 已完成 , 5: 待开团 , 6: 未中团
  1030. $in_num = array_rand($cgo->toArray(), $groupOrder['pin_number']);
  1031. foreach ($cgo->toArray() as $key => $val) {
  1032. if (in_array($key, (array)$in_num)) {
  1033. // 这里是拼中的 -- 修改订单状态 (拼团成功,等待发货)
  1034. model('common/GoodsOrder')->updateBy($val['id'], [
  1035. 'status' => 2
  1036. ]);
  1037. } else {
  1038. // 这里是拼不中-- 修改订单状态 (未中团,返款加限时红包,等待红包过期才关闭订单)
  1039. // 先返款
  1040. model('common/Users')->changeBalance(
  1041. $val['user_id'],
  1042. $pay_price,
  1043. "参团失败,退还支付金额【" . $pay_price . '】',
  1044. true
  1045. );
  1046. // 获取用户信息
  1047. $user = model('common/Users')->findBy($val['user_id']);
  1048. // 订阅消息
  1049. $this->tpl2['touser'] = $user['open_id'];
  1050. $this->wechat->subscribe_message->send($this->tpl2);
  1051. // 获取订单产品
  1052. $order_detail = model('common/GoodsOrderDetail')->getAll(['order_id' => $val['id']]);
  1053. // 单产品SKU库存回增
  1054. foreach ($order_detail as $goods) {
  1055. // 单产品SKU库存回增
  1056. model('common/GoodsSku')
  1057. ->where(['param' => enjson(str2arr($goods['spec']))])
  1058. ->setInc('stock', $goods['count']);
  1059. // 产品总库存更新
  1060. model('common/Goods')
  1061. ->where(['id' => $goods['goods_id']])
  1062. ->setInc('stock', $goods['count']);
  1063. }
  1064. // 再更新
  1065. model('common/GoodsOrder')->updateBy($val['id'], [
  1066. 'pin_rebate' => $rArr[$key + 1], //返现生成 -- 读取数据库配置
  1067. 'pin_rebate_expired' => time() + ($pin_rebate_expired_at * 3600), // x 3600 数据库配置
  1068. 'status' => 6
  1069. ]);
  1070. }
  1071. }
  1072. // 数据更新
  1073. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  1074. 'pay_price' => $pay_price,
  1075. 'paid_at' => time()
  1076. ]);
  1077. // 拼团完成
  1078. model('common/GoodsOrderGroup')->updateBy(['id' => $goodsOrder['group_id']], [
  1079. 'success_at' => time(), // 拼单成功时间
  1080. 'status' => 1 // 拼单状态完成
  1081. ]);
  1082. } else {
  1083. // 数据更新
  1084. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  1085. 'pay_price' => $pay_price,
  1086. 'paid_at' => time(),
  1087. 'status' => 5
  1088. ]);
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }