OrderService.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\AccountLogModel;
  13. use App\Models\CartModel;
  14. use App\Models\GoodsModel;
  15. use App\Models\GoodsSkuModel;
  16. use App\Models\MemberModel;
  17. use App\Models\OrderGoodsModel;
  18. use App\Models\OrderModel;
  19. use App\Models\StoreModel;
  20. use App\Services\BaseService;
  21. use App\Services\ConfigService;
  22. use App\Services\Kd100Service;
  23. use App\Services\PaymentService;
  24. use App\Services\RedisService;
  25. use Illuminate\Support\Facades\DB;
  26. /**
  27. * 订单-服务类
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. * @package App\Services\Api
  31. */
  32. class OrderService extends BaseService
  33. {
  34. // 静态对象
  35. protected static $instance = null;
  36. /**
  37. * 构造函数
  38. * @author laravel开发员
  39. * @since 2020/11/11
  40. */
  41. public function __construct()
  42. {
  43. $this->model = new OrderModel();
  44. }
  45. /**
  46. * 静态入口
  47. */
  48. public static function make()
  49. {
  50. if (!self::$instance) {
  51. self::$instance = new static();
  52. }
  53. return self::$instance;
  54. }
  55. /**
  56. * 订单列表
  57. * @param $params
  58. * @param int $pageSize
  59. * @return array
  60. */
  61. public function getDataList($params, $pageSize = 15)
  62. {
  63. $model = $this->getQuery($params);
  64. // 数据
  65. $list = $model->where(function ($query) use ($params) {
  66. $status = isset($params['status']) ? $params['status'] : 0;
  67. if ($status > 0 && is_array($status)) {
  68. $query->whereIn('a.status', $status)->where('a.refund_status', 0);
  69. } else if ($status == 6) {
  70. $query->where('a.status', '>', 1)->where('a.refund_status', '>', 0);
  71. } else if ($status > 0) {
  72. $query->where('a.status', $status)->where('a.refund_status', 0);
  73. }
  74. })->select(['a.*'])
  75. ->orderBy('a.id', 'desc')
  76. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  77. $list = $list ? $list->toArray() : [];
  78. if ($list) {
  79. $statusArr = [1 => '待支付', 2 => '待发货', 3 => '待收货', 4 => '确认收货'];
  80. foreach ($list['data'] as &$item) {
  81. $item['create_time'] = $item['create_time'] ? dateFormat(strtotime($item['create_time']), 'Y-m-d') : '';
  82. $status = isset($item['status']) ? $item['status'] : 0;
  83. $item['status_text'] = '待支付';
  84. if ($status) {
  85. $item['status_text'] = isset($statusArr[$status]) ? $statusArr[$status] : '';
  86. }
  87. if ($item['refund_status'] > 0) {
  88. $item['status_text'] = '退款/售后';
  89. }
  90. $item['goods'] = isset($item['goods']) && $item['goods'] ? $item['goods'] : [];
  91. $item['real_total'] = $item['pay_total'];
  92. $item['pay_total'] = moneyFormat($item['pay_total'] + $item['delivery_fee'], 2);
  93. }
  94. unset($item);
  95. }
  96. return [
  97. 'pageSize' => $pageSize,
  98. 'total' => isset($list['total']) ? $list['total'] : 0,
  99. 'list' => isset($list['data']) ? $list['data'] : []
  100. ];
  101. }
  102. /**
  103. * 查询条件
  104. * @param $params
  105. * @return mixed
  106. */
  107. public function getQuery($params)
  108. {
  109. $where = ['a.is_hide' => 0,'a.main_no'=>'', 'a.mark' => 1];
  110. return $this->model->from('orders as a')
  111. ->with(['orderGoods', 'store'])
  112. ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
  113. ->where($where)
  114. ->where(function ($query) use ($params) {
  115. $userId = isset($params['user_id']) ? intval($params['user_id']) : 0;
  116. if ($userId > 0) {
  117. $query->where('a.user_id', $userId);
  118. }
  119. // 订单类型
  120. $type = isset($params['type']) ? intval($params['type']) : 0;
  121. if ($type > 0) {
  122. $query->where('a.type', $type);
  123. }
  124. })
  125. ->where(function ($query) use ($params) {
  126. $keyword = isset($params['keyword']) ? $params['keyword'] : '';
  127. if ($keyword) {
  128. $query->where('a.order_no', 'like', "%{$keyword}%")
  129. ->orWhere('b.mobile', 'like', "%{$keyword}%");
  130. }
  131. });
  132. }
  133. /**
  134. * 订单详情
  135. * @param $id
  136. */
  137. public function getOrderInfo($id, $no = '')
  138. {
  139. $where = ['a.order_no' => $no, 'a.id' => $id, 'a.mark' => 1];
  140. if ($no) {
  141. unset($where['a.id']);
  142. } else {
  143. unset($where['a.order_no']);
  144. }
  145. $statusArr = [1 => '待支付', 2 => '待发货', 3 => '待收货', 4 => '已完成'];
  146. $info = $this->model->from('orders as a')
  147. ->with(['orderGoods', 'store'])
  148. ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
  149. ->where($where)
  150. ->select(['a.*'])
  151. ->first();
  152. if ($info) {
  153. $info = $info->toArray();
  154. $info['create_time'] = $info['create_time'] ? datetime($info['create_time'], 'Y-m-d H:i:s') : '';
  155. $info['pay_at'] = $info['pay_at'] ? datetime(strtotime($info['pay_at']), 'Y-m-d H:i:s') : '';
  156. $info['receiver_mobile_text'] = $info['receiver_mobile'] ? format_mobile($info['receiver_mobile']) : '';
  157. $info['real_total'] = $info['pay_total'];
  158. $info['pay_total'] = moneyFormat($info['pay_total'] + $info['delivery_fee'], 2);
  159. $status = isset($info['status']) ? $info['status'] : 0;
  160. $info['status_text'] = '待支付';
  161. if ($status) {
  162. $info['status_text'] = isset($statusArr[$status]) ? $statusArr[$status] : '';
  163. }
  164. }
  165. return $info;
  166. }
  167. /**
  168. * 创建订单
  169. * @param $userId 用户
  170. * @param $params 参数
  171. * @return array|false
  172. */
  173. public function createOrder($userId, $params)
  174. {
  175. $type = isset($params['type']) && $params['type'] ? $params['type'] : 1;
  176. $submitType = isset($params['submit_type']) && $params['submit_type'] ? $params['submit_type'] : '';
  177. $addressId = isset($params['address_id']) && $params['address_id'] ? $params['address_id'] : 0;
  178. $goods = isset($params['goods']) && $params['goods'] ? $params['goods'] : [];
  179. $ids = $goods ? array_column($goods, 'id') : [];
  180. // 参数验证
  181. if (empty($goods) || empty($ids)) {
  182. $this->error = '商品参数不为空';
  183. return false;
  184. }
  185. if ($addressId <= 0) {
  186. $this->error = '请选择收货地址';
  187. return false;
  188. }
  189. // 缓存锁
  190. $cacheLockKey = "caches:orders:submit_lock:{$userId}";
  191. if (RedisService::get($cacheLockKey)) {
  192. $this->error = '订单处理中~';
  193. return false;
  194. }
  195. // 用户信息
  196. RedisService::set($cacheLockKey, ['params' => $params, 'user_id' => $userId], rand(3, 5));
  197. $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
  198. ->select(['id', 'openid','nickname','member_level','parent_id','point_id','points', 'buy_type','property','balance', 'bd_score', 'status'])
  199. ->first();
  200. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  201. $openid = isset($userInfo['openid']) ? $userInfo['openid'] : 0;
  202. $buyType = isset($userInfo['buy_type']) ? $userInfo['buy_type'] : 0;
  203. $bdScore = isset($userInfo['bd_score']) ? $userInfo['bd_score'] : 0;
  204. $discountPoint = isset($userInfo['discount_point']) ? $userInfo['discount_point'] : 0; // 折扣
  205. if (empty($userInfo) || $status != 1) {
  206. $this->error = 1045;
  207. return false;
  208. }
  209. if (empty($openid)) {
  210. $this->error = 1042;
  211. return false;
  212. }
  213. // 商品数据
  214. $orderNo = get_order_num('JK');
  215. $result = GoodsService::make()->getOrderGoods($ids, $goods, $userId, $orderNo, $discountPoint);
  216. if (empty($result)) {
  217. RedisService::clear($cacheLockKey);
  218. $this->error = GoodsService::make()->getError();
  219. return false;
  220. }
  221. $orderGoods = isset($result['goods']) ? $result['goods'] : [];
  222. $goodsTotal = isset($result['goods_total']) ? $result['goods_total'] : 0; // 商品总价
  223. $orderTotal = isset($result['order_total']) ? $result['order_total'] : 0; // 订单结算金额(折后)
  224. $bdScoreTotal = isset($result['bd_score_total']) ? $result['bd_score_total'] : 0; // 报单积分
  225. $profitTotal = isset($result['profit_total']) ? $result['profit_total'] : 0; // 利润
  226. $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 折扣金额
  227. $orderCount = isset($result['count']) ? $result['count'] : 0;
  228. $deliveryFee = isset($result['delivery_fee']) ? $result['delivery_fee'] : 0; // 运费
  229. $storeId = isset($result['store_id']) ? $result['store_id'] : 0; // 企业/商家
  230. if (empty($orderGoods)) {
  231. RedisService::clear($cacheLockKey);
  232. $this->error = '获取订单商品错误~';
  233. return false;
  234. }
  235. if ($orderTotal <= 0) {
  236. RedisService::clear($cacheLockKey);
  237. $this->error = '订单金额错误~';
  238. return false;
  239. }
  240. if ($orderCount <= 0) {
  241. RedisService::clear($cacheLockKey);
  242. $this->error = '订单商品数量错误~';
  243. return false;
  244. }
  245. // 创业大礼包
  246. $mealId = 0;
  247. if ($type == 2) {
  248. $mealId = isset($ids[0]) ? $ids[0] : 0;
  249. if ($buyType != $mealId) {
  250. RedisService::clear($cacheLockKey);
  251. $this->error = '该礼包您暂时不满足购买条件';
  252. return false;
  253. }
  254. // 报单积分是否够
  255. if ($bdScore < $bdScoreTotal) {
  256. RedisService::clear($cacheLockKey);
  257. $this->error = '抱歉,您的报单积分不足';
  258. return false;
  259. }
  260. // 是否购买过
  261. $buyLimit = ConfigService::make()->getConfigByCode('business_buy_limit', 0);
  262. $buyLimit = $buyLimit>0?$buyLimit:0;
  263. if($buyLimit>0){
  264. $checkOrderCount = $this->checkBusinessOrder($userId, $mealId);
  265. if ($checkOrderCount >= $buyLimit) {
  266. RedisService::clear($cacheLockKey);
  267. $this->error = $buyLimit>1?"抱歉该创业礼包仅限购买{$buyLimit}次":'抱歉,您已经购买过该礼包';
  268. return false;
  269. }
  270. }
  271. }
  272. // 收货地址信息
  273. $addressInfo = MemberAddressService::make()->getBindInfo($userId, $addressId);
  274. $realname = isset($addressInfo['realname']) ? $addressInfo['realname'] : '';
  275. $mobile = isset($addressInfo['mobile']) ? $addressInfo['mobile'] : '';
  276. $area = isset($addressInfo['area']) ? $addressInfo['area'] : '';
  277. $address = isset($addressInfo['address']) ? $addressInfo['address'] : '';
  278. if (empty($addressInfo) || empty($realname) || empty($mobile) || empty($area) || empty($address)) {
  279. RedisService::clear($cacheLockKey);
  280. $this->error = '收货地址信息错误,请核对后重试~';
  281. return false;
  282. }
  283. // 是否开启分账功能
  284. $payTotal = moneyFormat($orderTotal + $deliveryFee, 2); // 含运费支付金额
  285. if (env('PAY_DEBUG')) {
  286. $payTotal = 0.01;
  287. }
  288. // 订单数据
  289. $order = [
  290. 'order_no' => $orderNo,
  291. 'user_id' => $userId,
  292. 'store_id' => $storeId,
  293. 'meal_id' => $mealId,
  294. 'type' => $type,
  295. 'total' => $goodsTotal, // 商品总价
  296. 'num' => $orderCount,
  297. 'bd_score' => $bdScoreTotal, // 折扣后商品总价(不含运费)
  298. 'profit_total' => $profitTotal, // 折扣后商品总价(不含运费)
  299. 'pay_money' => $orderTotal, // 折扣后商品总价(不含运费)
  300. 'pay_total' => $type==2?moneyFormat($orderTotal + $bdScoreTotal,2):$orderTotal, // 折扣后商品总价(不含运费)
  301. 'pay_status' => $type==2? 30 : 10, // 折扣后商品总价(不含运费)
  302. 'discount_point' => $discountPoint,
  303. 'discount_total' => $discountTotal, // 折扣金额
  304. 'delivery_fee' => $deliveryFee, // 运费
  305. 'receiver_name' => $realname,
  306. 'receiver_mobile' => $mobile,
  307. 'receiver_area' => $area,
  308. 'receiver_address' => $address,
  309. 'create_time' => time(),
  310. 'update_time' => time(),
  311. 'status' => 1,
  312. 'mark' => 1,
  313. ];
  314. // 订单处理
  315. DB::beginTransaction();
  316. if (!$orderId = $this->model->insertGetId($order)) {
  317. DB::rollBack();
  318. $this->error = '创建订单失败';
  319. RedisService::clear($cacheLockKey);
  320. return false;
  321. }
  322. // 订单商品
  323. if ($orderGoods && !OrderGoodsModel::insert($orderGoods)) {
  324. DB::rollBack();
  325. $this->error = '处理订单商品错误';
  326. RedisService::clear($cacheLockKey);
  327. return false;
  328. }
  329. // 创业礼包分单
  330. if ($type == 2) {
  331. $data = $order;
  332. $data['total'] = moneyFormat($data['total'] / 6);
  333. $data['bd_score'] = moneyFormat($bdScoreTotal / 6, 2);
  334. $data['profit_total'] = moneyFormat($profitTotal / 6, 2);
  335. $data['pay_total'] = moneyFormat($orderTotal / 6, 2);
  336. $data['pay_money'] = moneyFormat($order['pay_money'] / 6, 2);
  337. $subOrders = [];
  338. for ($i = 1; $i <= 6; $i++) {
  339. $data['order_no'] = get_order_num('BS');
  340. $data['main_no'] = $orderNo;
  341. if ($i == 6) {
  342. $data['total'] = round($order['total'] / 6, 2);
  343. $data['bd_score'] = round($bdScoreTotal / 6, 2);
  344. $data['profit_total'] = round($profitTotal / 6, 2);
  345. $data['pay_total'] = round($orderTotal / 6, 2);
  346. $data['pay_money'] = round($order['pay_money'] / 6, 2);
  347. }
  348. $subOrders[] = $data;
  349. }
  350. //
  351. if ($subOrders && !$this->model->insert($subOrders)) {
  352. DB::rollBack();
  353. $this->error = '处理商品订单失败';
  354. RedisService::clear($cacheLockKey);
  355. return false;
  356. }
  357. // 扣除报单积分
  358. if($bdScoreTotal>0){
  359. if(!MemberModel::where(['id'=>$userId])->update(['bd_score'=>DB::raw("bd_score - {$bdScoreTotal}"),'update_time'=>time()])){
  360. DB::rollBack();
  361. $this->error = '报单积分扣除失败';
  362. RedisService::clear($cacheLockKey);
  363. return false;
  364. }
  365. $data = [
  366. 'user_id'=>$userId,
  367. 'source_order_no'=>$orderNo,
  368. 'user_type'=> 1,
  369. 'account_type'=> 3, // 报单积分
  370. 'type'=> 1,
  371. 'money'=> -$bdScoreTotal,
  372. 'after_money'=>moneyFormat($bdScore - $bdScoreTotal,2),
  373. 'date'=>date('Y-m-d'),
  374. 'create_time'=>time(),
  375. 'remark'=> '创业礼包支付',
  376. 'status'=>1,
  377. 'mark'=>1
  378. ];
  379. if(!AccountLogModel::insertGetId($data)){
  380. Db::rollBack();
  381. $this->error = '付款处理失败';
  382. return false;
  383. }
  384. }
  385. }
  386. // 佣金数据
  387. if(!$commission = SettleService::make()->commissionCount($order,$orderGoods,$userInfo, $type)){
  388. Db::rollBack();
  389. $this->error = '订单处理失败';
  390. return false;
  391. }
  392. // 获取支付参数
  393. /* TODO 支付处理 */
  394. $payOrder = [
  395. 'type' => 1,
  396. 'order_no' => $orderNo,
  397. 'is_revenue' => isset($order['is_revenue'])?$order['is_revenue']:2,
  398. 'pay_money' => $payTotal,
  399. 'body' => '订单付款',
  400. 'openid' => $openid
  401. ];
  402. // 调起支付
  403. $payment = PaymentService::make()->minPay($userInfo, $payOrder, 'store');
  404. if (empty($payment)) {
  405. //DB::rollBack();
  406. RedisService::clear($cacheLockKey);
  407. $this->error = PaymentService::make()->getError();
  408. return false;
  409. }
  410. // 商品库存扣除
  411. if ($orderGoods) {
  412. foreach ($orderGoods as $item) {
  413. $id = isset($item['goods_id']) ? $item['goods_id'] : 0;
  414. $num = isset($item['num']) ? $item['num'] : 0;
  415. $skuId = isset($item['sku_id']) ? $item['sku_id'] : 0;
  416. if ($id && !GoodsModel::where(['id' => $id])->update(['stock' => DB::raw("stock - {$num}"), 'update_time' => time()])) {
  417. DB::rollBack();
  418. RedisService::clear($cacheLockKey);
  419. $this->error = '商品库存处理失败';
  420. return false;
  421. }
  422. if ($skuId && !GoodsSkuModel::where(['id' => $skuId])->update(['stock' => DB::raw("stock - {$num}"), 'update_time' => time()])) {
  423. DB::rollBack();
  424. RedisService::clear($cacheLockKey);
  425. $this->error = '商品库存处理失败';
  426. return false;
  427. }
  428. }
  429. // 清空购物车结算商品
  430. if($submitType == 'cart'){
  431. $skuIds = $goods ? array_column($goods, 'sku_id') : [];
  432. CartModel::whereIn('goods_id',$ids)->whereIn('sku_id',$skuIds)->where(['user_id'=>$userId,'mark'=>1])->update(['mark'=>0,'num'=>0,'update_time'=>time()]);
  433. RedisService::clear("caches:goods:cartCount:{$userId}");
  434. }
  435. }
  436. // 用户操作记录
  437. DB::commit();
  438. $this->error = '订单创建成功,请前往支付~';
  439. RedisService::clear($cacheLockKey);
  440. return [
  441. 'order_id' => $orderId,
  442. 'payment' => $payment,
  443. 'total' => $payOrder['pay_money'],
  444. 'pay_type' => 10,
  445. ];
  446. }
  447. /**
  448. * 创业大礼包验证
  449. * @param $userId
  450. * @param $goodsId
  451. * @return array|mixed
  452. */
  453. public function checkBusinessOrder($userId, $goodsId)
  454. {
  455. $cacheKey = "caches:orders:check_order:{$userId}_{$goodsId}";
  456. $data = RedisService::get($cacheKey);
  457. if ($data) {
  458. return $data;
  459. }
  460. $data = $this->model->where(['user_id' => $userId, 'meal_id' => $goodsId, 'mark' => 1])
  461. ->where('status', '<=', 5)
  462. ->where('refund_status', '<=', 0)
  463. ->count('id');
  464. $data = $data ? $data->toArray() : [];
  465. if ($data) {
  466. RedisService::set($cacheKey, $data, rand(5, 10));
  467. }
  468. return $data;
  469. }
  470. /**
  471. * 订单支付
  472. * @param $userId
  473. * @param $id
  474. * @return array|false
  475. */
  476. public function pay($userId, $id)
  477. {
  478. if ($id <= 0) {
  479. $this->error = '请选择支付订单';
  480. return false;
  481. }
  482. // 缓存锁
  483. $cacheLockKey = "caches:orders:pay_lock:{$userId}_{$id}";
  484. if (RedisService::get($cacheLockKey)) {
  485. $this->error = '订单处理中~';
  486. return false;
  487. }
  488. // 商品数据
  489. RedisService::set($cacheLockKey, ['order_id' => $id, 'user_id' => $userId], rand(3, 5));
  490. // 用户信息
  491. $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
  492. ->select(['id', 'openid', 'mobile', 'nickname', 'realname', 'balance', 'status'])
  493. ->first();
  494. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  495. $openid = isset($userInfo['openid']) ? $userInfo['openid'] : '';
  496. if (empty($userInfo) || $status != 1) {
  497. $this->error = 1045;
  498. RedisService::clear($cacheLockKey);
  499. return false;
  500. }
  501. if (empty($openid)) {
  502. $this->error = '用户微信未授权,请重新授权登录';
  503. RedisService::clear($cacheLockKey);
  504. return false;
  505. }
  506. // 订单信息
  507. $info = $this->model->where(['id' => $id, 'mark' => 1])
  508. ->select(['id', 'order_no', 'pay_total', 'delivery_fee', 'status'])
  509. ->first();
  510. $orderTotal = isset($info['pay_total']) ? $info['pay_total'] : 0;
  511. $deliveryFee = isset($info['delivery_fee']) ? $info['delivery_fee'] : 0;
  512. $orderNo = isset($info['order_no']) ? $info['order_no'] : '';
  513. $status = isset($info['status']) ? $info['status'] : 0;
  514. if (empty($info) || empty($orderNo)) {
  515. $this->error = '订单信息不存在';
  516. RedisService::clear($cacheLockKey);
  517. return false;
  518. }
  519. if ($status != 1) {
  520. $this->error = '订单已支付';
  521. RedisService::clear($cacheLockKey);
  522. return false;
  523. }
  524. // 获取支付参数
  525. /* TODO 支付处理 */
  526. $payOrder = [
  527. 'type' => 1,
  528. 'order_no' => $orderNo,
  529. 'pay_money' => moneyFormat($orderTotal + $deliveryFee),
  530. 'body' => '购物消费',
  531. 'openid' => $openid
  532. ];
  533. // 调起支付
  534. $payment = PaymentService::make()->minPay($userInfo, $payOrder, 'store');
  535. if (empty($payment)) {
  536. DB::rollBack();
  537. RedisService::clear($cacheLockKey);
  538. $this->error = PaymentService::make()->getError();
  539. return false;
  540. }
  541. // 用户操作记录
  542. DB::commit();
  543. $this->error = '支付请求成功,请前往支付~';
  544. RedisService::clear($cacheLockKey);
  545. return [
  546. 'order_id' => $id,
  547. 'payment' => $payment,
  548. 'total' => $payOrder['pay_money'],
  549. 'pay_type' => 10,
  550. ];
  551. }
  552. /**
  553. * 订单取消
  554. * @param $userId
  555. * @param $orderId
  556. * @return array|false
  557. */
  558. public function cancel($userId, $orderId)
  559. {
  560. if ($orderId <= 0) {
  561. $this->error = '请选择订单';
  562. return false;
  563. }
  564. // 缓存锁
  565. $cacheLockKey = "caches:orders:cancel_lock:{$userId}_{$orderId}";
  566. if (RedisService::get($cacheLockKey)) {
  567. $this->error = '订单处理中~';
  568. return false;
  569. }
  570. RedisService::set($cacheLockKey, ['order_id' => $orderId, 'user_id' => $userId], rand(3, 5));
  571. // 用户信息
  572. $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
  573. ->select(['id', 'openid', 'mobile', 'nickname', 'realname', 'balance', 'status'])
  574. ->first();
  575. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  576. if (empty($userInfo) || $status != 1) {
  577. $this->error = 1045;
  578. RedisService::clear($cacheLockKey);
  579. return false;
  580. }
  581. // 订单信息
  582. $info = $this->model->where(['id' => $orderId, 'mark' => 1])
  583. ->select(['id', 'order_no', 'pay_total', 'status'])
  584. ->first();
  585. $orderNo = isset($info['order_no']) ? $info['order_no'] : '';
  586. $status = isset($info['status']) ? $info['status'] : 0;
  587. if (empty($info) || empty($orderNo)) {
  588. $this->error = '订单信息不存在';
  589. RedisService::clear($cacheLockKey);
  590. return false;
  591. }
  592. if ($status != 1) {
  593. $this->error = '订单已支付';
  594. RedisService::clear($cacheLockKey);
  595. return false;
  596. }
  597. $orderGoods = OrderGoodsModel::where(['order_no' => $orderNo, 'mark' => 1])
  598. ->select(['goods_id', 'num', 'sku_id'])
  599. ->get();
  600. DB::beginTransaction();
  601. if ($orderGoods) {
  602. foreach ($orderGoods as $goods) {
  603. $goodsId = isset($goods['goods_id']) ? $goods['goods_id'] : 0;
  604. $num = isset($goods['num']) ? $goods['num'] : 0;
  605. $skuId = isset($goods['sku_id']) ? $goods['sku_id'] : 0;
  606. if ($goodsId) {
  607. GoodsModel::where(['id' => $goodsId])->update(['stock' => DB::raw("stock + {$num}"), 'update_time' => time()]);
  608. }
  609. if ($skuId) {
  610. GoodsSkuModel::where(['id' => $skuId])->update(['stock' => DB::raw("stock + {$num}"), 'update_time' => time()]);
  611. }
  612. }
  613. }
  614. $this->error = '取消订单成功';
  615. $this->model->where(['user_id' => $userId, 'mark' => 0])->where('update_time', '<=', time() - 300)->delete();
  616. OrderGoodsModel::where(['order_no' => $orderNo, 'mark' => 0])->where('update_time', '<=', time() - 300)->delete();
  617. $this->model->where(['id' => $orderId])->update(['mark' => 0, 'update_time' => time()]);
  618. OrderGoodsModel::where(['order_no' => $orderNo])->update(['mark' => 0, 'update_time' => time()]);
  619. DB::commit();
  620. return ['id' => $orderId];
  621. }
  622. /**
  623. * 订单删除隐藏
  624. * @param $userId
  625. * @param $orderId
  626. * @return array|false
  627. */
  628. public function hide($userId, $orderId)
  629. {
  630. if ($orderId <= 0) {
  631. $this->error = '请选择订单';
  632. return false;
  633. }
  634. // 缓存锁
  635. $cacheLockKey = "caches:orders:hide_lock:{$userId}_{$orderId}";
  636. if (RedisService::get($cacheLockKey)) {
  637. $this->error = '订单删除中~';
  638. return false;
  639. }
  640. RedisService::set($cacheLockKey, ['order_id' => $orderId, 'user_id' => $userId], rand(3, 5));
  641. // 用户信息
  642. $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
  643. ->select(['id', 'openid', 'mobile', 'nickname', 'realname', 'balance', 'status'])
  644. ->first();
  645. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  646. if (empty($userInfo) || $status != 1) {
  647. $this->error = 1045;
  648. RedisService::clear($cacheLockKey);
  649. return false;
  650. }
  651. // 订单信息
  652. $info = $this->model->where(['id' => $orderId, 'mark' => 1])
  653. ->select(['id', 'order_no', 'pay_total', 'status'])
  654. ->first();
  655. $orderNo = isset($info['order_no']) ? $info['order_no'] : '';
  656. $status = isset($info['status']) ? $info['status'] : 0;
  657. if (empty($info) || empty($orderNo)) {
  658. $this->error = '订单信息不存在';
  659. RedisService::clear($cacheLockKey);
  660. return false;
  661. }
  662. if ($status != 4) {
  663. $this->error = '订单未完成';
  664. RedisService::clear($cacheLockKey);
  665. return false;
  666. }
  667. $this->error = '删除订单成功';
  668. $this->model->where(['id' => $orderId])->update(['is_hide' => 1, 'update_time' => time()]);
  669. return ['id' => $orderId];
  670. }
  671. /**
  672. * 订单完成
  673. * @param $userId 订单用户ID
  674. * @param $id 订单ID
  675. * @return array|false
  676. */
  677. public function complete($userId, $id, $check = true)
  678. {
  679. if ($id <= 0) {
  680. $this->error = '请选择订单';
  681. return false;
  682. }
  683. // 缓存锁
  684. $cacheLockKey = "caches:orders:complete_lock:{$userId}_{$id}";
  685. if (RedisService::get($cacheLockKey)) {
  686. $this->error = '订单处理中~';
  687. return false;
  688. }
  689. // 商品数据
  690. RedisService::set($cacheLockKey, ['order_id' => $id, 'user_id' => $userId], rand(3, 5));
  691. // 用户信息
  692. $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
  693. ->select(['id', 'openid', 'mobile', 'parent_id', 'nickname', 'realname', 'balance', 'status'])
  694. ->first();
  695. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  696. $parentId = isset($userInfo['parent_id']) ? $userInfo['parent_id'] : 0;
  697. if ($check && (empty($userInfo) || $status != 1)) {
  698. $this->error = 1045;
  699. RedisService::clear($cacheLockKey);
  700. return false;
  701. }
  702. // 订单信息
  703. $info = $this->model->with(['orderGoods','commission'])->where(['id' => $id, 'mark' => 1])
  704. ->select(['id', 'order_no','type', 'user_id', 'store_id', 'total', 'pay_total', 'delivery_no', 'delivery_company', 'delivery_code', 'status'])
  705. ->first();
  706. $orderNo = isset($info['order_no']) ? $info['order_no'] : '';
  707. $deliveryNo = isset($info['delivery_no']) ? $info['delivery_no'] : '';
  708. $deliverCompany = isset($info['delivery_company']) ? $info['delivery_company'] : '';
  709. $orderUserId = isset($info['user_id']) ? $info['user_id'] : 0;
  710. $storeId = isset($info['store_id']) ? $info['store_id'] : 0;
  711. $orderType = isset($info['type']) ? $info['type'] : 0;
  712. $orderTotal = isset($info['total']) ? $info['total'] : 0;
  713. $status = isset($info['status']) ? $info['status'] : 0;
  714. $commission = isset($info['commission']) ? $info['commission'] : [];
  715. $bonus = isset($commission['bonus'])?$commission['bonus'] : 0;
  716. $orderGoods = isset($info['order_goods']) ? $info['order_goods'] : [];
  717. if (empty($info) || empty($orderNo)) {
  718. $this->error = '订单信息不存在';
  719. RedisService::clear($cacheLockKey);
  720. return false;
  721. }
  722. if ($status != 3) {
  723. $this->error = '订单未发货';
  724. RedisService::clear($cacheLockKey);
  725. return false;
  726. }
  727. if (empty($deliveryNo) || empty($deliverCompany)) {
  728. $this->error = '订单发货信息错误,请联系客服';
  729. $this->model->where(['id' => $id])->update(['is_complete' => 1, 'complete_remark' => $this->error]);
  730. RedisService::clear("caches:orders:completeList");
  731. RedisService::clear($cacheLockKey);
  732. return false;
  733. }
  734. DB::beginTransaction();
  735. $completeStatus = env('ORDER_COMPLETE_STATUS', 5);
  736. $updateData = ['status' => $completeStatus, 'complete_at' => date('Y-m-d H:i:s'), 'update_time' => time()];
  737. if (!$check) {
  738. $updateData['is_complete'] = 1;
  739. $updateData['complete_remark'] = '自动收货';
  740. }
  741. $this->model->where(['id' => $id])->update($updateData);
  742. // 商家订单数据统计
  743. $updateData = ['order_count' => DB::raw('order_count+1'), 'order_total' => DB::raw("order_total + {$orderTotal}")];
  744. StoreModel::where(['id' => $storeId])->update($updateData);
  745. // 商品销量数据
  746. if ($orderGoods) {
  747. $counts = [];
  748. foreach ($orderGoods as $item) {
  749. $counts[$item['goods_id']] = isset($counts[$item['goods_id']]) ? $counts[$item['goods_id']] : 0;
  750. $counts[$item['goods_id']] += $item['num'];
  751. }
  752. if ($counts) {
  753. foreach ($counts as $id => $v) {
  754. GoodsModel::where(['id' => $id])->update(['sales' => DB::raw("sales + {$v}"), 'update_time' => time()]);
  755. }
  756. }
  757. }
  758. // 结算商家收益
  759. if ($bonus && SettleService::make()->storeBonus($storeId, $bonus, $info) < 0) {
  760. DB::rollBack();
  761. $this->error = SettleService::make()->getError();
  762. RedisService::clear($cacheLockKey);
  763. return false;
  764. }
  765. if($orderType==2){
  766. // 创业礼包结算
  767. if (SettleService::make()->businessBonus($orderUserId, $orderTotal, $commission, $info) < 0) {
  768. DB::rollBack();
  769. $this->error = SettleService::make()->getError();
  770. RedisService::clear($cacheLockKey);
  771. return false;
  772. }
  773. }else{
  774. // 商城奖励结算
  775. if (SettleService::make()->shopBonus($orderUserId, $orderTotal,$commission, $info) < 0) {
  776. DB::rollBack();
  777. $this->error = SettleService::make()->getError();
  778. RedisService::clear($cacheLockKey);
  779. return false;
  780. }
  781. }
  782. DB::commit();
  783. $this->error = '确认收货成功';
  784. RedisService::clear("caches:orders:completeList");
  785. RedisService::clear("caches:orders:revenueList");
  786. return ['id' => $id, 'msg' => $this->error];
  787. }
  788. /**
  789. * 售后或退款
  790. * @param $userId
  791. * @param $params
  792. * @return array|false
  793. */
  794. public function after($userId, $params)
  795. {
  796. $id = isset($params['id']) ? $params['id'] : 0;
  797. $afterType = isset($params['after_type']) ? $params['after_type'] : 1;
  798. if ($id <= 0) {
  799. $this->error = '请选择订单';
  800. return false;
  801. }
  802. // 缓存锁
  803. $cacheLockKey = "caches:orders:after_lock:{$userId}_{$id}";
  804. if (RedisService::get($cacheLockKey)) {
  805. $this->error = '订单处理中~';
  806. return false;
  807. }
  808. // 商品数据
  809. RedisService::set($cacheLockKey, ['params' => $params, 'user_id' => $userId], rand(3, 5));
  810. // 用户信息
  811. $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
  812. ->select(['id', 'openid', 'mobile', 'nickname', 'realname', 'balance', 'status'])
  813. ->first();
  814. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  815. if (empty($userInfo) || $status != 1) {
  816. $this->error = 1045;
  817. RedisService::clear($cacheLockKey);
  818. return false;
  819. }
  820. // 订单信息
  821. $info = $this->model->where(['id' => $id, 'mark' => 1])
  822. ->select(['id', 'order_no', 'after_type', 'refund_status', 'pay_total', 'status'])
  823. ->first();
  824. $orderNo = isset($info['order_no']) ? $info['order_no'] : '';
  825. $status = isset($info['status']) ? $info['status'] : 0;
  826. $refundStatus = isset($info['refund_status']) ? $info['refund_status'] : 0;
  827. if (empty($info) || empty($orderNo)) {
  828. $this->error = '订单信息不存在';
  829. RedisService::clear($cacheLockKey);
  830. return false;
  831. }
  832. if ($status == 1) {
  833. $this->error = '订单未支付';
  834. RedisService::clear($cacheLockKey);
  835. return false;
  836. }
  837. if ($status == 4 && $afterType == 2) {
  838. $this->error = '订单已完成';
  839. RedisService::clear($cacheLockKey);
  840. return false;
  841. }
  842. if ($refundStatus > 0 && $refundStatus != 4) {
  843. $this->error = '订单售后处理中';
  844. RedisService::clear($cacheLockKey);
  845. return false;
  846. }
  847. $afterRealname = isset($params['after_realname']) ? $params['after_realname'] : '';
  848. $afterPhone = isset($params['after_phone']) ? $params['after_phone'] : '';
  849. $afterRemark = isset($params['after_remark']) ? $params['after_remark'] : '';
  850. if ($afterType == 1) {
  851. if (empty($afterRealname) || empty($afterPhone) || empty($afterRemark)) {
  852. $this->error = '请填写售后信息';
  853. RedisService::clear($cacheLockKey);
  854. return false;
  855. }
  856. }
  857. $data = [
  858. 'after_type' => $afterType,
  859. 'after_realname' => $afterRealname,
  860. 'after_phone' => $afterPhone,
  861. 'after_remark' => $afterRemark,
  862. 'refund_remark' => isset($params['refund_remark']) ? $params['refund_remark'] : '',
  863. 'refund_status' => 3,
  864. 'update_time' => time()
  865. ];
  866. $this->model->where(['id' => $id])->update($data);
  867. $this->error = '订单申请售后成功';
  868. return ['id' => $id];
  869. }
  870. /**
  871. * 物流查询
  872. * @param $id
  873. * @return array|false|mixed
  874. */
  875. public function getDelivery($id)
  876. {
  877. $info = $this->model->where(['id' => $id, 'mark' => 1])->first();
  878. $deliveryNo = isset($info['delivery_no']) ? $info['delivery_no'] : '';
  879. $deliveryCode = isset($info['delivery_code']) ? $info['delivery_code'] : '';
  880. $mobile = isset($info['receiver_mobile']) ? $info['receiver_mobile'] : '';
  881. $receiverArea = isset($info['receiver_area']) && $info['receiver_area'] ? $info['receiver_area'] : '';
  882. if (empty($info)) {
  883. $this->error = '请选择订单';
  884. return false;
  885. }
  886. $cacheKey = "caches:kd100:order_{$id}";
  887. $data = RedisService::get($cacheKey);
  888. if ($data) {
  889. return $data;
  890. }
  891. $result = Kd100Service::make()->query($deliveryNo, $mobile, $deliveryCode, $receiverArea);
  892. RedisService::set($cacheKey . '_result', $result, 300);
  893. $status = isset($result['status']) ? $result['status'] : 0;
  894. $data = isset($result['data']) ? $result['data'] : [];
  895. $courierInfo = isset($result['courierInfo']) ? $result['courierInfo'] : [];
  896. $arrivalTime = isset($result['arrivalTime']) ? $result['arrivalTime'] : '';
  897. $predictedRoute = isset($result['predictedRoute']) ? $result['predictedRoute'] : [];
  898. $predictedData = $predictedRoute ? end($predictedRoute) : [];
  899. $arrivalData = [];
  900. if ($arrivalTime) {
  901. $arrivalData['arrivalTime'] = dayFormat(strtotime($arrivalTime . ':00:00'));
  902. $arrivalData['predictedData'] = $predictedData;
  903. }
  904. if ($courierInfo && $courierInfo['deliveryManPhone']) {
  905. $courierInfo['deliveryManPhone'] = explode(',', $courierInfo['deliveryManPhone']);
  906. $courierInfo['deliveryPhone'] = $courierInfo['deliveryManPhone'][1] ? $courierInfo['deliveryManPhone'][1] : $courierInfo['deliveryManPhone'][0];
  907. }
  908. if ($data && $status == 200) {
  909. RedisService::set($cacheKey, ['info' => $courierInfo, 'arrivalData' => $arrivalData, 'list' => $data], 1200);
  910. }
  911. return $data ? ['info' => $courierInfo, 'arrivalData' => $arrivalData, 'list' => $data] : [];
  912. }
  913. /**
  914. * 已发货待完成订单
  915. * @return array|mixed
  916. */
  917. public function getCompleteOrders()
  918. {
  919. $cacheKey = "caches:orders:completeList";
  920. $datas = RedisService::get($cacheKey);
  921. if ($datas) {
  922. return $datas;
  923. }
  924. $completeDay = ConfigService::make()->getConfigByCode('order_complete_day', 7);
  925. $limitNum = ConfigService::make()->getConfigByCode('order_complete_batch_num', 300);
  926. $limitNum = $limitNum > 10 && $limitNum < 2000 ? $limitNum : 300;
  927. $completeDay = $completeDay >= 1 && $completeDay < 30 ? $completeDay : 7;
  928. $datas = $this->model->where(['status' => 3, 'is_complete' => 2, 'mark' => 1])
  929. ->whereNotNull('delivery_no')
  930. ->select(['id', 'user_id', 'order_no', 'status'])
  931. ->where('pay_at', '<=', date('Y-m-d H:i:s', time() - $completeDay * 86400))
  932. ->limit($limitNum)
  933. ->get();
  934. $datas = $datas ? $datas->toArray() : [];
  935. if ($datas) {
  936. RedisService::set($cacheKey, $datas, rand(300, 600));
  937. }
  938. return $datas;
  939. }
  940. /**
  941. * 已完成,待分账订单
  942. * @return array|mixed
  943. */
  944. public function getRevenueOrderList()
  945. {
  946. $cacheKey = "caches:orders:revenueList";
  947. $datas = RedisService::get($cacheKey);
  948. if ($datas) {
  949. return $datas;
  950. }
  951. $limitNum = ConfigService::make()->getConfigByCode('order_revenue_batch_num', 300);
  952. $limitNum = $limitNum > 10 && $limitNum < 2000 ? $limitNum : 300;
  953. $datas = $this->model->where(['status' => 4, 'is_revenue' => 1, 'revenue_status' => 2, 'mark' => 1])
  954. ->select(['id', 'user_id', 'pay_total', 'order_no', 'revenue_no', 'transaction_id', 'status'])
  955. ->limit($limitNum)
  956. ->get();
  957. $datas = $datas ? $datas->toArray() : [];
  958. if ($datas) {
  959. RedisService::set($cacheKey, $datas, rand(300, 600));
  960. }
  961. return $datas;
  962. }
  963. /**
  964. * 订单分账处理
  965. * @param $id
  966. * @return false
  967. * @throws \Yansongda\Pay\Exception\ContainerException
  968. * @throws \Yansongda\Pay\Exception\InvalidParamsException
  969. */
  970. public function revenue($id)
  971. {
  972. if ($id <= 0) {
  973. $this->error = '订单参数错误';
  974. return false;
  975. }
  976. // 缓存锁
  977. $cacheLockKey = "caches:orders:revenue_lock:{$id}";
  978. if (RedisService::get($cacheLockKey)) {
  979. $this->error = '订单分账处理中~';
  980. return false;
  981. }
  982. // 是否设置分账账户
  983. $revenueOpenid = ConfigService::make()->getConfigByCode('order_revenue_openid', '');
  984. if (empty($revenueOpenid)) {
  985. $this->error = '订单分账账户未配置';
  986. return false;
  987. }
  988. // 订单信息
  989. RedisService::set($cacheLockKey, ['id' => $id, 'date' => date('Y-m-d H:i:s')], 20);
  990. $info = $this->model->where(['id' => $id, 'mark' => 1])
  991. ->select(['id', 'order_no', 'revenue_no', 'user_id', 'transaction_id', 'pay_total', 'is_revenue', 'revenue_status', 'revenue_amount', 'status'])
  992. ->first();
  993. $revenueOrderNo = isset($info['revenue_no']) ? $info['revenue_no'] : '';
  994. $revenueAmount = isset($info['revenue_amount']) ? $info['revenue_amount'] : 0;
  995. $status = isset($info['status']) ? $info['status'] : 0;
  996. $isRevenue = isset($info['is_revenue']) ? $info['is_revenue'] : 0;
  997. $revenueStatus = isset($info['revenue_status']) ? $info['revenue_status'] : 0;
  998. if ($status != 4) {
  999. RedisService::clear($cacheLockKey);
  1000. $this->error = '订单状态错误,未完成收货的订单无法分账';
  1001. return false;
  1002. }
  1003. if ($isRevenue != 1) {
  1004. RedisService::clear($cacheLockKey);
  1005. $this->error = '该订单不是分账订单';
  1006. return false;
  1007. }
  1008. if ($revenueStatus != 2) {
  1009. RedisService::clear($cacheLockKey);
  1010. $this->error = '该订单分账已处理完成';
  1011. return false;
  1012. }
  1013. if ($revenueAmount <= 0) {
  1014. RedisService::clear($cacheLockKey);
  1015. $this->error = '订单分账金额不足';
  1016. return false;
  1017. }
  1018. $order = [
  1019. 'transaction_id' => $info['transaction_id'],
  1020. 'out_order_no' => $revenueOrderNo,
  1021. 'body' => '订单分账',
  1022. 'amount' => $revenueAmount,
  1023. 'unsplit' => true, // 只分一次
  1024. ];
  1025. $result = PaymentService::make()->profitsharing($revenueOpenid, $order);
  1026. $state = isset($result->state) ? $result->state : 0;
  1027. $message = isset($result->message) ? $result->message : '分账失败';
  1028. $orderId = isset($result->order_id) ? $result->order_id : '';
  1029. if ($state == 'FINISHED') {
  1030. $this->model->where(['id' => $id])->update(['revenue_status' => 1, 'revenue_order_id' => $orderId, 'update_time' => time()]);
  1031. RedisService::clear($cacheLockKey);
  1032. RedisService::clear("caches:orders:revenueList");
  1033. $this->error = '分账处理成功';
  1034. return true;
  1035. } else {
  1036. RedisService::clear($cacheLockKey);
  1037. $this->error = $message;
  1038. return false;
  1039. }
  1040. }
  1041. }