Wechat.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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. if (!Users::where(['id' => $goodsOrder['user_id']])->inc('taxi_property', $goodsOrder['price'])) {
  505. return $fail('司机资产更新失败');
  506. }
  507. $thing5 = '尊敬的用户您好,您的升级订单已经支付成功!';
  508. break;
  509. case "motor_agent":
  510. $UserPaymentOrder = new UserPaymentOrder();
  511. $goodsOrder = $UserPaymentOrder->with('agent,user')
  512. ->field('id,user_id,order_no,status')
  513. ->find($orderId);
  514. // 更新订单信息
  515. $goodsOrder->status = 2;
  516. $goodsOrder->save();
  517. // 更新摩的代理
  518. $goodsOrder->agent->status = 40;
  519. $goodsOrder->agent->save();
  520. // 更新用户信息
  521. $goodsOrder->user->is_motor_agent = 2;
  522. $goodsOrder->user->save();
  523. break;
  524. case "motor_driver":
  525. $UserPaymentOrder = new UserPaymentOrder();
  526. $goodsOrder = $UserPaymentOrder->with('driver')
  527. ->field('id,user_id,order_no,status')
  528. ->find($orderId);
  529. // 更新订单信息
  530. $goodsOrder->status = 2;
  531. $goodsOrder->save();
  532. // 更新摩的代理
  533. $goodsOrder->driver->status = 1;
  534. $goodsOrder->driver->save();
  535. }
  536. // 获取用户
  537. $user = model('common/Users')->getBy(['id' => $goodsOrder['user_id']]);
  538. // 用户消费金额处理
  539. // 写入本次消费后总金额
  540. $user_consume_total = $user['consume'] + $pay_price;
  541. model('common/Users')->updateBy($goodsOrder['user_id'], [
  542. 'consume' => sprintf('%.2f', $user_consume_total)
  543. ]);
  544. // 3.查找用户消费获得资产奖励
  545. if ($order['ascription'] == 'goods') {
  546. // 消费总额包含 商品、接单、技能、摩的
  547. // 获取资产设置
  548. $user_property_reward = sys_config('user_property_reward', 'user');
  549. if ($user_property_reward != '') {
  550. foreach (str2arr($user_property_reward, ',') as $key => $reward) {
  551. list($select, $amount) = str2arr($reward, ":");
  552. if ($amount == 0) continue;
  553. // 当前总消费达到奖励
  554. if ($user_consume_total >= $select && $key == $user['property_count']) {
  555. //TODO 达到消费 -- 反奖励
  556. model('common/Users')->changeProperty(
  557. $goodsOrder['user_id'],
  558. sprintf("%.2f", round($amount, 2)),
  559. "消费满 {$select},平台奖励资产【" . sprintf("%.2f", round($amount, 2)) . '】',
  560. true
  561. );
  562. // 增加领取次数
  563. model('common/Users')->where(['id' => $goodsOrder['user_id']])
  564. ->setInc('property_count');
  565. }
  566. }
  567. }
  568. }
  569. // 模板消息
  570. $this->tpl1['touser'] = $user['open_id'];
  571. $this->tpl1['data'] = [
  572. 'character_string1' => [
  573. 'value' => $goodsOrder['order_no'],
  574. ],
  575. 'thing3' => [
  576. 'value' => $tplTitle,
  577. ],
  578. 'amount4' => [
  579. 'value' => $pay_price,
  580. ],
  581. 'date2' => [
  582. 'value' => date("Y/m/d H:i:s"),
  583. ],
  584. 'thing7' => [
  585. 'value' => $thing5,
  586. ]
  587. ];
  588. $this->wechat->subscribe_message->send($this->tpl1);
  589. }
  590. return true;
  591. } else {
  592. return $fail('支付失败,请稍后再通知我');
  593. }
  594. });
  595. Db::commit();
  596. return $response->send(); // Laravel 里请使用:return $response;
  597. } catch (Exception $e) {
  598. app()->log('支付错误:' . $e->getMessage(),'pay');
  599. Db::rollback();
  600. return $this->ApiJson(-1, "支付返回时错误!" . $e->getMessage());
  601. }
  602. }
  603. /**
  604. * 获取小程序分享码
  605. *
  606. * @return \think\response\Json
  607. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  608. * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
  609. * @throws \Lettered\Support\Exceptions\FailedException
  610. * @throws \think\db\exception\DataNotFoundException
  611. * @throws \think\db\exception\ModelNotFoundException
  612. * @throws \think\exception\DbException
  613. * @author 许祖兴 < zuxing.xu@lettered.cn>
  614. * @date 2020/6/26 18:11
  615. *
  616. */
  617. public function getShareSpread()
  618. {
  619. // 获取用户信息
  620. $user = $this->auth->user();
  621. // 获取邀请信息
  622. $spread = model('common/UsersInvite')
  623. ->where(['user_id' => $user['id']])->find();
  624. // 存在性判断
  625. if (!$spread) {
  626. // 邀请码就选择用户ID
  627. $response = $this->wechat->app_code->getUnlimit('spd=' . $user['card_id'], [
  628. // 'scene' => [
  629. // 'spd' => $user['card_id']
  630. // ],
  631. 'page' => 'pages/index/index',
  632. 'width' => 600,
  633. 'line_color' => [
  634. 'r' => 236,
  635. 'g' => 108,
  636. 'b' => 68,
  637. ]
  638. ]);
  639. // 检查
  640. if (is_array($response) && $response['errcode'] == '41030') {
  641. return $this->ApiJson(-1, '当前体验版无法生成二维码,请上线后重试~');
  642. }
  643. // 保存二维码
  644. if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
  645. $filename = $response->saveAs($this->app->getRootPath() . 'public/uploads/spread', md5(time()) . '.png');
  646. $qrImg = get_annex_url('/spread/' . $filename);
  647. //TODO 二维码写入数据库
  648. model('common/UsersInvite')->storeBy([
  649. 'user_id' => $user['id'],
  650. 'code' => $user['card_id'],
  651. 'qr_img' => $qrImg
  652. ]);
  653. return $this->ApiJson(0, 'OK!', [
  654. 'inviteCode' => $user['card_id'],
  655. 'qrcodeImg' => $qrImg
  656. ]);
  657. }
  658. return $this->ApiJson(-1, '生成邀请失败,请稍后重试~');
  659. }
  660. return $this->ApiJson(0, 'OK!', [
  661. 'inviteCode' => $spread['code'],
  662. 'qrcodeImg' => $spread['qr_img']
  663. ]);
  664. }
  665. private function thirdPayment($channel, $paylog)
  666. {
  667. // 目前就微信支付
  668. // 加载配置
  669. $wechat = sys_config('', $channel);
  670. // 发起支付
  671. $config = [
  672. // 前面的appid什么的也得保留哦
  673. 'app_id' => $wechat['mini_appid'],
  674. 'mch_id' => $wechat['pay_mch_id'],
  675. 'key' => $wechat['pay_secret_key'],
  676. // 'notify_url' => 'https://api.gxrrj.cn/api/v1/wechat/notify',
  677. 'notify_url' => site_url() . '/api/v1/wechat/notify',
  678. // 'notify_url' => 'http://ncnjmz.natappfree.cc/api/v1/wechat/notify',
  679. // 'sandbox' => true
  680. ];
  681. app()->log(json_encode($config, 256),'wechat');
  682. // 创建应用实例
  683. $payment = Factory::payment($config);
  684. $jssdk = $payment->jssdk;
  685. // 服务名称
  686. $serve = "";
  687. switch ($paylog['ascription']) {
  688. case 'farmland':
  689. $serve = "田地服务";
  690. break;
  691. case 'motor':
  692. $serve = "摩的服务";
  693. break;
  694. case 'skill':
  695. $serve = "技能服务";
  696. break;
  697. case 'mission':
  698. $serve = "配送服务";
  699. break;
  700. case 'goods':
  701. $serve = "商品购买";
  702. break;
  703. case 'level':
  704. $serve = "司机付费升级";
  705. break;
  706. }
  707. // 统一下单
  708. $result = $payment->order->unify([
  709. 'attach' => $paylog['ascription'], // 附加数据,区分订单所属
  710. 'body' => '人人接 - ' . $serve,
  711. 'out_trade_no' => $paylog['out_trade_no'],
  712. 'total_fee' => round($paylog['total_price'] * 100),
  713. 'trade_type' => 'JSAPI',
  714. 'openid' => $this->auth->user()['open_id']
  715. ]);
  716. app()->log('提交支付' . enjson($result), 'debug');
  717. if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
  718. return $this->ApiJson(0, '', $jssdk->sdkConfig($result['prepay_id']));
  719. }
  720. return $this->ApiJson(-1, isset($result['return_msg']) ? $result['return_msg'] : '支付异常,请稍后重试...');
  721. }
  722. private function thirdRefund($channel, $paylog)
  723. {
  724. // 1.查找对应是否有退款订单
  725. // 2.创建退款单记录
  726. // 3.请求微信退款
  727. // 参数分别为:微信订单号、商户退款单号、订单金额、退款金额、其他参数
  728. //$app->refund->byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $config = []);
  729. // Example:
  730. $result = $app->refund->byTransactionId($paylog['out_trade_no'], 'refund-no-xxx', 10000, 10000, [
  731. // 可在此处传入其他参数,详细参数见微信支付文档
  732. 'refund_desc' => '商品已售完',
  733. ]);
  734. }
  735. /**
  736. * 余额支付
  737. *
  738. * @param $payType
  739. * @param $paylog
  740. * @return \think\response\Json
  741. * @throws \Lettered\Support\Exceptions\FailedException
  742. * @throws \think\Exception
  743. * @throws \think\db\exception\DataNotFoundException
  744. * @throws \think\db\exception\ModelNotFoundException
  745. * @throws \think\exception\DbException
  746. * @throws \think\exception\PDOException
  747. * @author 许祖兴 < zuxing.xu@lettered.cn>
  748. * @date 2020/8/6 16:39
  749. *
  750. */
  751. private function buyOnUserSelf($payType = 'balance', $paylog)
  752. {
  753. // 检查用户余额
  754. $user = $this->auth->user();
  755. if ($user[$payType] < $paylog['total_price']) {
  756. return $this->ApiJson(-1, '支付失败,账户余额不足!');
  757. }
  758. // 支付金额
  759. $pay_price = sprintf("%.2f", round($paylog['total_price'], 2));
  760. Db::startTrans();
  761. try {
  762. // 支付成功 支付订单状态is_pay =1
  763. model('common/OrderPaylog')->updateBy($paylog['id'], [
  764. 'pay_price' => $pay_price,
  765. 'pay_type' => $payType, // 默认支付方式
  766. 'is_pay' => 1,
  767. ]);
  768. $orderId = $paylog['order_idx'];
  769. // 模板消息标题
  770. $tplTitle = "";
  771. $thing7 = '感谢您的支持,我们将致力于更好的服务!';
  772. $goodsOrder = 1;
  773. switch ($paylog['ascription']) {
  774. // 田地订单
  775. case "farmland":
  776. $goodsOrder = model('common/FarmlandOrder')->getBy(['id' => $orderId]);
  777. $tplTitle = "人人接 - 田地服务";
  778. model('common/FarmlandOrder')->updateBy($orderId, ['status' => 2, 'pay_type' => $payType]);
  779. // todo 停止本次招标
  780. model('common/FarmlandBlock')->updateBy($goodsOrder['block_id'], [
  781. 'status' => 2 // 1 可用 2 服务中
  782. ]);
  783. push_socket_data('farmland', [
  784. 'id' => $orderId,
  785. 'msg' => '有新的农田订单等待处理,点击前往!'
  786. ]);
  787. break;
  788. // 摩的订单
  789. case "motor":
  790. $goodsOrder = model('common/TaxiOrder')->getBy(['id' => $orderId]);
  791. $tplTitle = "人人接 - 摩的服务";
  792. model('common/TaxiOrder')->updateBy($orderId, ['status' => 2]);
  793. push_socket_data('motor', [
  794. 'id' => $orderId,
  795. 'msg' => '有新的摩的订单等待处理,点击前往!'
  796. ]);
  797. // 订阅消息
  798. // $thing7 = '电话请保持通畅,师傅正在赶往路上,请稍候';
  799. // 订单结算给摩的代理
  800. //model('\app\api\model\taxi\Award')->send($goodsOrder);
  801. break;
  802. // 技能订单
  803. case "skill":
  804. $tplTitle = "人人接 - 技能服务";
  805. $goodsOrder = model('common/SkillOrder')->getBy(['id' => $orderId]);
  806. model('common/SkillOrder')->updateBy($orderId, ['status' => 2]);
  807. push_socket_data('skill', [
  808. 'id' => $orderId,
  809. 'msg' => '有新的技能订单等待处理,点击前往!'
  810. ]);
  811. break;
  812. // 配送订单
  813. case "mission":
  814. $tplTitle = "人人接 - 配送服务";
  815. $goodsOrder = model('common/MissionOrder')->getBy(['id' => $orderId]);
  816. model('common/MissionOrder')->updateBy($orderId, ['status' => 2]);
  817. push_socket_data('mission', [
  818. 'id' => $orderId,
  819. 'msg' => '有新的配送订单等待处理,点击前往!'
  820. ]);
  821. break;
  822. // 救援订单
  823. case "rescue":
  824. $tplTitle = "人人接 - 救援服务";
  825. $goodsOrder = model('common/RescueOrder')->getBy(['id' => $orderId]);
  826. model('common/RescueOrder')->updateBy($orderId, ['status' => 2]);
  827. push_socket_data('rescue', [
  828. 'id' => $orderId,
  829. 'msg' => '有新的救援订单等待处理,点击前往!'
  830. ]);
  831. break;
  832. // 商品订单
  833. case "goods":
  834. // 获取订单产品
  835. $goods = model('common/GoodsOrderDetail')->where(['order_id' => $paylog['order_idx']])->find();
  836. $tplTitle = $goods['title'];
  837. // 产品订单
  838. $goodsOrder = model('common/GoodsOrder')->where(['id' => $paylog['order_idx']])->lock(true)->find();
  839. // 获取当前支付订单是否为拼团
  840. if ($goodsOrder && $goodsOrder['is_pin']) {
  841. $this->dealWithPinOrder($pay_price, $goodsOrder);
  842. } else {
  843. // 0: 已关闭 1:待支付, 2:待发货,3:待收货 , 4: 已完成 , 5: 待开团 , 6: 未中团
  844. // 数据更新
  845. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  846. 'pay_price' => $pay_price,
  847. 'paid_at' => time(),
  848. 'status' => 2
  849. ]);
  850. }
  851. push_socket_data('goods', [
  852. 'id' => $goodsOrder['id'],
  853. 'msg' => '有新的商品订单等待处理,点击前往!'
  854. ]);
  855. break;
  856. }
  857. //$user = model('common/Users')->getBy(['id' => $goodsOrder['user_id']]);
  858. // 扣减账户余额
  859. if ($payType == 'balance') {
  860. model('common/Users')->changeBalance(
  861. $user['id'],
  862. $pay_price,
  863. "支付成功,支付金额【" . $pay_price . "】"
  864. );
  865. } else if ($payType == 'property') {
  866. model('common/Users')->changeProperty(
  867. $user['id'],
  868. $pay_price,
  869. "消费成功,消费资产【{$pay_price}】"
  870. );
  871. }
  872. // 查找用户消费获得资产奖励 - 资产消费无法获得资产
  873. if ($paylog['ascription'] == 'goods' && $payType != 'property') {
  874. // 用户消费金额处理
  875. // 写入本次消费后总金额
  876. $user_consume_total = $user['consume'] + $pay_price;
  877. model('common/Users')->updateBy($user['id'], [
  878. 'consume' => sprintf('%.2f', $user_consume_total)
  879. ]);
  880. // 消费总额包含 商品、接单、技能、摩的
  881. // 获取资产设置
  882. $user_property_reward = sys_config('user_property_reward', 'user');
  883. if ($user_property_reward != '') {
  884. foreach (str2arr($user_property_reward, ',') as $key => $reward) {
  885. list($select, $amount) = str2arr($reward, ":");
  886. if ($amount == 0) continue;
  887. // 当前总消费达到奖励
  888. if ($user_consume_total >= $select && $key == $user['property_count']) {
  889. //TODO 达到消费 -- 反奖励
  890. model('common/Users')->changeProperty(
  891. $goodsOrder['user_id'],
  892. sprintf("%.2f", round($amount, 2)),
  893. "消费满 {$select},平台奖励资产【" . sprintf("%.2f", round($amount, 2)) . '】',
  894. true
  895. );
  896. // 增加领取次数
  897. model('common/Users')->where(['id' => $goodsOrder['user_id']])
  898. ->setInc('property_count');
  899. }
  900. }
  901. }
  902. }
  903. // 模板消息
  904. $this->tpl1['touser'] = $user['open_id'];
  905. $this->tpl1['data'] = [
  906. 'character_string1' => [
  907. 'value' => $goodsOrder['order_no'],
  908. ],
  909. 'thing3' => [
  910. 'value' => $tplTitle,
  911. ],
  912. 'amount4' => [
  913. 'value' => $pay_price,
  914. ],
  915. 'date2' => [
  916. 'value' => date("Y/m/d H:i:s"),
  917. ],
  918. 'thing7' => [
  919. 'value' => $thing7,
  920. ]
  921. ];
  922. // $this->wechat->subscribe_message->send($this->tpl1);
  923. Db::commit();
  924. return $this->ApiJson(0, '支付成功');
  925. } catch (\Exception $e) {
  926. Log::error('支付错误:' . $e->getMessage() . $e->getTraceAsString());
  927. Db::rollback();
  928. return $this->ApiJson(-1, $e->getMessage());
  929. }
  930. }
  931. private function dealWithPinOrder($pay_price, $goodsOrder)
  932. {
  933. // 拼单详情
  934. $gorder_detail = model('common/GoodsOrderDetail')->getBy(['order_id' => $goodsOrder['id']]);
  935. // 查拼单产品
  936. $goods = model('common/Goods')->where(['id' => $gorder_detail['goods_id']])->lock(true)->find();
  937. // 支付成功 -- 0 为创建拼团
  938. if ($goodsOrder['group_id'] == 0) {
  939. $joinId = model('common/GoodsOrderGroup')->storeBy([
  940. 'user_id' => $goodsOrder['user_id'],
  941. 'goods_id' => $goods['id'],
  942. 'pin_sum' => $goods['pin_sum'],
  943. 'pin_number' => $goods['pin_number'],
  944. // 超时时间
  945. 'expired_at' => time() + (sys_config('pin_expired_at', 'store') * 3600) // 24 * 3600
  946. ]);
  947. // 数据更新
  948. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  949. 'group_id' => $joinId, //创建的时候追加拼团id
  950. 'pay_price' => $pay_price,
  951. 'paid_at' => time(),
  952. 'status' => 5
  953. ]);
  954. } else { // 参加拼团 -- 增加人数
  955. $groupOrder = model('common/GoodsOrderGroup')->where(['id' => $goodsOrder['group_id']])->lock(true)->find();
  956. // 1. 是否已经拼满了,或者已经拼单成功了 -- 拼单满了就直接拼单失败,直接返回金额到余额,关闭订单开启限时红白奖励
  957. if (($groupOrder['pin_sum'] == $groupOrder['now_number']) || $groupOrder['status'] == 1) {
  958. // 关闭我的订单 -- 这里应该直接关闭订单直接返款,没有红包
  959. // 先返款
  960. model('common/Users')->changeBalance(
  961. $goodsOrder['user_id'],
  962. $pay_price,
  963. "参团失败,退还支付金额【" . $pay_price . '】',
  964. true
  965. );
  966. // 单产品SKU库存回增
  967. model('common/GoodsSku')
  968. ->where(['param' => enjson(str2arr($gorder_detail['spec']))])
  969. ->setInc('stock', $gorder_detail['count']);
  970. // 产品总库存更新
  971. model('common/Goods')
  972. ->where(['id' => $gorder_detail['goods_id']])
  973. ->setInc('stock', $gorder_detail['count']);
  974. // 销量减
  975. model('common/Goods')
  976. ->where(['id' => $gorder_detail['goods_id']])
  977. ->setDec('sell_count', $gorder_detail['count']);
  978. // 再更新 -- 关闭订单
  979. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  980. 'pay_price' => $pay_price,
  981. 'paid_at' => time(),
  982. 'status' => 0
  983. ]);
  984. } else {
  985. // pin_sum 拼团人数
  986. // pin_number 获得人数
  987. // now_number 当前人数
  988. // 2. 加入拼单成功,检查我是不是最后一个,最后一个直接开团,获得者从随机获得
  989. $gog = model('common/GoodsOrderGroup')->where(['id' => $goodsOrder['group_id']]);
  990. $gog->setInc('now_number', $gorder_detail['count']);
  991. // 当前人数检查 -- 达到拼团人数--开团
  992. if ($groupOrder['pin_sum'] == $gog->value("now_number")) {
  993. // 当前拼单成团 - 进行逻辑发放
  994. // 查找当前拼团下的所有订单
  995. $cgo = model('common/GoodsOrder')
  996. ->where(['group_id' => $groupOrder['id']])
  997. ->select();
  998. // 利润 count * ( total_price - instock )
  999. // 总利润
  1000. $cgo_total = 0;
  1001. // 子单
  1002. foreach ($cgo as $item) {
  1003. // 子单明细
  1004. $its = model('common/GoodsOrderDetail')->where(['order_id' => $item['id']])->select();
  1005. foreach ($its as $itsv) {
  1006. // 产品
  1007. $goin = model('common/GoodsSku')->where(['goods_id' => $itsv['goods_id'], 'param' => enjson(str2arr($itsv['spec'], ','))])->value('instock_price');
  1008. $cgo_total += sprintf("%.2f", round($itsv['total_price'] - $goin, 2));
  1009. }
  1010. }
  1011. // todo 返现生成如果是按百分比和整数混合
  1012. $pin_rebate_amount = sys_config('pin_rebate_amount', 'store');
  1013. $pin_rebate_expired_at = sys_config('pin_rebate_expired_at', 'store');
  1014. // 20200730 客户说按利润比得数据
  1015. // 利润 * 比例 = 要发放的钱
  1016. $rebate = sprintf("%.2f", round($cgo_total * (float)$pin_rebate_amount / 100, 2));
  1017. $num = count($cgo);// 分成10个红包,支持10人随机领取
  1018. $min = 0.01 * $rebate;//每个人最少能收到0.01元
  1019. $rArr = [];
  1020. for ($i = 1; $i < $num; $i++) {
  1021. $safe_total = ($rebate - ($num - $i) * $min) / ($num - $i);//随机安全上限
  1022. $money = mt_rand($min * 100, $safe_total * 100) / 100;
  1023. $rebate -= $money;
  1024. $rArr[$i] = $money;
  1025. }
  1026. $rArr[$num] = $rebate;
  1027. //TODO 暂时脑子瓦特,想不到什么好办法
  1028. // 0: 已关闭 1:待支付, 2:待发货,3:待收货 , 4: 已完成 , 5: 待开团 , 6: 未中团
  1029. $in_num = array_rand($cgo->toArray(), $groupOrder['pin_number']);
  1030. foreach ($cgo->toArray() as $key => $val) {
  1031. if (in_array($key, (array)$in_num)) {
  1032. // 这里是拼中的 -- 修改订单状态 (拼团成功,等待发货)
  1033. model('common/GoodsOrder')->updateBy($val['id'], [
  1034. 'status' => 2
  1035. ]);
  1036. } else {
  1037. // 这里是拼不中-- 修改订单状态 (未中团,返款加限时红包,等待红包过期才关闭订单)
  1038. // 先返款
  1039. model('common/Users')->changeBalance(
  1040. $val['user_id'],
  1041. $pay_price,
  1042. "参团失败,退还支付金额【" . $pay_price . '】',
  1043. true
  1044. );
  1045. // 获取用户信息
  1046. $user = model('common/Users')->findBy($val['user_id']);
  1047. // 订阅消息
  1048. $this->tpl2['touser'] = $user['open_id'];
  1049. $this->wechat->subscribe_message->send($this->tpl2);
  1050. // 获取订单产品
  1051. $order_detail = model('common/GoodsOrderDetail')->getAll(['order_id' => $val['id']]);
  1052. // 单产品SKU库存回增
  1053. foreach ($order_detail as $goods) {
  1054. // 单产品SKU库存回增
  1055. model('common/GoodsSku')
  1056. ->where(['param' => enjson(str2arr($goods['spec']))])
  1057. ->setInc('stock', $goods['count']);
  1058. // 产品总库存更新
  1059. model('common/Goods')
  1060. ->where(['id' => $goods['goods_id']])
  1061. ->setInc('stock', $goods['count']);
  1062. }
  1063. // 再更新
  1064. model('common/GoodsOrder')->updateBy($val['id'], [
  1065. 'pin_rebate' => $rArr[$key + 1], //返现生成 -- 读取数据库配置
  1066. 'pin_rebate_expired' => time() + ($pin_rebate_expired_at * 3600), // x 3600 数据库配置
  1067. 'status' => 6
  1068. ]);
  1069. }
  1070. }
  1071. // 数据更新
  1072. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  1073. 'pay_price' => $pay_price,
  1074. 'paid_at' => time()
  1075. ]);
  1076. // 拼团完成
  1077. model('common/GoodsOrderGroup')->updateBy(['id' => $goodsOrder['group_id']], [
  1078. 'success_at' => time(), // 拼单成功时间
  1079. 'status' => 1 // 拼单状态完成
  1080. ]);
  1081. } else {
  1082. // 数据更新
  1083. model('common/GoodsOrder')->updateBy($goodsOrder['id'], [
  1084. 'pay_price' => $pay_price,
  1085. 'paid_at' => time(),
  1086. 'status' => 5
  1087. ]);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }