Placeorder.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <?php
  2. namespace app\admin\controller\store;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\order\StoreOrder as StoreOrderModel;
  5. use app\admin\model\order\StoreOrderStatus;
  6. use app\admin\model\system\ShippingTemplates;
  7. use app\admin\model\system\SystemStore;
  8. use app\models\store\StoreBargainUser;
  9. use app\models\store\StoreBargainUserHelp;
  10. use app\models\store\StoreCart;
  11. use app\models\store\StoreCouponUser;
  12. use app\models\store\StoreOrder;
  13. use app\models\store\StorePink;
  14. use app\models\system\CardInfo;
  15. use app\models\system\SystemStoreMember;
  16. use app\models\system\SystemStoreStock;
  17. use app\models\user\User;
  18. use app\models\user\UserAddress;
  19. use app\models\user\UserLevel;
  20. use app\Request;
  21. use crmeb\repositories\OrderRepository;
  22. use think\facade\Route as Url;
  23. use crmeb\services\{FormBuilder, UtilService as Util, JsonService as Json, UtilService};
  24. use app\admin\model\store\StoreProductAttrValue;
  25. /**
  26. *
  27. * Class Placeorder
  28. * @package app\admin\controller\store
  29. */
  30. class Placeorder extends AuthController
  31. {
  32. /**
  33. * 购物车 列表
  34. * @param Request $request
  35. * @return mixed
  36. */
  37. public function lst()
  38. {
  39. return app('json')->successful(StoreCart::getUserProductCartList($this->request->get('uid'), '', 0, $this->adminInfo['store_id']));
  40. }
  41. /**
  42. * 下单
  43. * @return string
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function index()
  49. {
  50. $store = [];
  51. if ($this->adminInfo['type'] == 0) {
  52. $store = SystemStore::where('is_del', 0)->where('is_show', 1)->field('id,name')->select()->toArray();
  53. } else {
  54. $store = SystemStore::where('id', $this->adminInfo['store_id'])->field('id,name')->select();
  55. }
  56. $this->assign('store', $store);
  57. $this->assign('type', $this->adminInfo['type']);
  58. return $this->fetch();
  59. }
  60. /**
  61. * 获取会员卡
  62. * @param $card_no
  63. */
  64. public function getCardNo($card_no)
  65. {
  66. if ($card_no == '') return app('json')->fail('会员码不能为空');
  67. if (intval($card_no) == 1) {
  68. $info['user'] = User::where('uid', $card_no)->field("uid,real_name,addres , phone, '' as nickname, now_money,integral")->find();
  69. $info['uid'] = $info['user']['uid'];
  70. return app('json')->successful($info);
  71. }
  72. if (strlen($card_no) == 15) {
  73. $info = CardInfo::where(['type' => 1, 'card_number' => $card_no])->find();
  74. if (!$info) return app('json')->fail('充值卡号不存在');
  75. if ($info['use_uid'] == 0) return app('json')->fail('充值卡未激活');
  76. $info['user'] = User::where('uid', $info['use_uid'])->field('uid,real_name,addres,phone,nickname,now_money,integral')->find();
  77. $info['uid'] = $info['user']['uid'];
  78. return app('json')->successful($info);
  79. }
  80. if (strlen($card_no) == 8 || strlen($card_no) == 11) {
  81. if (!User::where('SN|phone', $card_no)->find()) return app('json')->fail('会员码不存在');
  82. $info['user'] = User::where('SN|phone', $card_no)->field('uid,real_name,addres,phone,nickname,now_money,integral')->find();
  83. $info['uid'] = $info['user']['uid'];
  84. } else {
  85. if (!SystemStoreMember::be(['card_no' => $card_no])) return app('json')->fail('会员码不存在');
  86. $info = SystemStoreMember::where('card_no', $card_no)->find()->toArray();
  87. $info['user'] = User::where('uid', $info['uid'])->field('real_name,addres,phone,nickname,now_money,integral')->find();
  88. }
  89. return app('json')->successful($info);
  90. }
  91. /**
  92. * 获取条形码商品
  93. * @param string $bar_code
  94. * @return array|void
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\DbException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. */
  99. public function getBarCode($bar_code = '')
  100. {
  101. if ($bar_code == '') return $this->failed('条形码不存在');
  102. $info = SystemStoreStock::alias('a')->join("StoreProduct b", "a.product_id=b.id", "left")->where('a.bar_code', $bar_code)->field('a.price,a.unique,a.in_stock,a.is_consumer,a.product_id,b.store_name,b.image')->find();
  103. if ($info) {
  104. $info = $info->toArray();
  105. $info['suk'] = StoreProductAttrValue::where('unique', $info['unique'])->value('suk');
  106. } else {
  107. $info = StoreProductAttrValue::alias('a')->join("StoreProduct b", "a.product_id=b.id", "left")->where('a.bar_code', $bar_code)->where('a.type', 0)->field('a.price,a.unique,0 as in_stock,b.is_consumer,a.product_id,b.store_name,b.image')->find();
  108. if ($info) {
  109. $info = $info->toArray();
  110. } else {
  111. $info = [];
  112. }
  113. }
  114. $product = \app\admin\model\store\StoreProduct::get($info['product_id']);
  115. $discounts = json_decode($product['time_area_discount'], true);
  116. $discount = 0;
  117. if (count($discounts) > 0) {
  118. foreach ($discounts as $kk => $v) {
  119. $times = explode('-', $kk);
  120. if (!(count($times) == 2)) {
  121. break;
  122. }
  123. $start = strtotime(date('Y-m-d') . $times[0]);
  124. $end = strtotime(date('Y-m-d') . $times[1]);
  125. if (time() > $start && time() <= $end) {
  126. $discount = $v;
  127. }
  128. }
  129. }
  130. if ($discount > 0) {
  131. $info['price'] = bcmul(bcdiv($discount, 100, 4), $info['price'], 2);
  132. }
  133. return app('json')->successful($info);
  134. }
  135. /**
  136. * 增加购物车
  137. * @param $data
  138. * @return mixed
  139. * @throws \think\db\exception\DataNotFoundException
  140. * @throws \think\db\exception\ModelNotFoundException
  141. */
  142. public function add_cart()
  143. {
  144. list($productId, $cartNum, $uniqueId, $combinationId, $secKillId, $bargainId, $new, $uid) = UtilService::postMore([
  145. ['productId', 0],//普通产品编号
  146. ['cartNum', 1], //购物车数量
  147. ['uniqueId', ''],//属性唯一值
  148. ['combinationId', 0],//拼团产品编号
  149. ['secKillId', 0],//秒杀产品编号
  150. ['bargainId', 0],//砍价产品编号
  151. ['new', 1], // 1 加入购物车直接购买 0 加入购物车
  152. ['uid', 0],//用户编号
  153. ], $this->request, true);
  154. $request = $this->request;
  155. if (!$productId || !is_numeric($productId)) return app('json')->fail('参数错误');
  156. if ($bargainId && StoreBargainUserHelp::getSurplusPrice($bargainId, $uid)) return app('json')->fail('请先砍价');
  157. $res = StoreCart::setCart($uid, $productId, $cartNum, $uniqueId, 'product', $new, $combinationId, $secKillId, $bargainId, 0, $this->adminInfo['store_id']);
  158. if (!$res) return app('json')->fail(StoreCart::getErrorInfo());
  159. else return app('json')->successful('ok', ['cartId' => $res->id]);
  160. }
  161. /**
  162. * 清空购物车
  163. * @return mixed
  164. * @throws \Exception
  165. */
  166. public function clear_cart()
  167. {
  168. list($uid) = UtilService::postMore([
  169. ['uid', 0],//用户编号
  170. ], $this->request, true);
  171. $is_pay = 0;
  172. $store_id = $this->adminInfo['store_id'];
  173. StoreCart::where(compact('uid', 'is_pay', 'store_id'))->delete();
  174. return app('json')->successful('清空完成!');
  175. }
  176. /**
  177. * 购物车 删除产品
  178. * @param Request $request
  179. * @return mixed
  180. */
  181. public function del(Request $request)
  182. {
  183. list($ids, $uid) = UtilService::postMore([
  184. ['ids', []],//购物车编号
  185. ['uid', 0],
  186. ], $request, true);
  187. if (!count($ids))
  188. return app('json')->fail('参数错误!');
  189. if (StoreCart::removeUserCart($uid, $ids))
  190. return app('json')->successful();
  191. return app('json')->fail('清除失败!');
  192. }
  193. /**
  194. * 购物车 修改产品数量
  195. * @param Request $request
  196. * @return mixed
  197. * @throws \think\Exception
  198. * @throws \think\db\exception\DataNotFoundException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. * @throws \think\exception\DbException
  201. */
  202. public function num(Request $request)
  203. {
  204. list($id, $number, $uid) = UtilService::postMore([
  205. ['id', 0],//购物车编号
  206. ['number', 0],//购物车编号
  207. ['uid', 0],
  208. ], $request, true);
  209. if (!$id || !$number || !is_numeric($id) || !is_numeric($number)) return app('json')->fail('参数错误!');
  210. $res = StoreCart::changeUserCartNum($id, $number, $uid);
  211. if ($res) return app('json')->successful();
  212. else return app('json')->fail(StoreCart::getErrorInfo('修改失败'));
  213. }
  214. /**
  215. * 订单确认
  216. * @return mixed
  217. * @throws \Psr\SimpleCache\InvalidArgumentException
  218. * @throws \think\db\exception\DataNotFoundException
  219. * @throws \think\db\exception\DbException
  220. * @throws \think\db\exception\ModelNotFoundException
  221. */
  222. public function confirm()
  223. {
  224. $request = $this->request;
  225. $temp = ShippingTemplates::get(1);
  226. if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
  227. list($cartId) = UtilService::postMore(['cartId'], $request, true);
  228. if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品1');
  229. $uid = input('uid', 0);
  230. $cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
  231. if (count($cartGroup['invalid'])) return app('json')->fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
  232. if (!$cartGroup['valid']) return app('json')->fail('请提交购买的商品2');
  233. $cartInfo = $cartGroup['valid'];
  234. $addr = UserAddress::where('uid', $uid)->where('is_default', 1)->find();
  235. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
  236. if ($priceGroup === false) {
  237. return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
  238. }
  239. $other = [
  240. 'offlinePostage' => sys_config('offline_postage'),
  241. 'integralRatio' => sys_config('integral_ratio')
  242. ];
  243. $usableCoupons = StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
  244. $usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
  245. $cartIdA = explode(',', $cartId);
  246. $seckill_id = 0;
  247. $combination_id = 0;
  248. $bargain_id = 0;
  249. if (count($cartIdA) == 1) {
  250. $seckill_id = StoreCart::where('id', $cartId)->value('seckill_id');
  251. $combination_id = StoreCart::where('id', $cartId)->value('combination_id');
  252. $bargain_id = StoreCart::where('id', $cartId)->value('bargain_id');
  253. }
  254. $data['deduction'] = $seckill_id || $combination_id || $bargain_id;
  255. $data['usableCoupon'] = $usableCoupon;
  256. $data['addressInfo'] = UserAddress::getUserDefaultAddress($uid);
  257. $data['seckill_id'] = $seckill_id;
  258. $data['combination_id'] = $combination_id;
  259. $data['bargain_id'] = $bargain_id;
  260. $data['cartInfo'] = $cartInfo;
  261. $data['priceGroup'] = $priceGroup;
  262. $data['orderKey'] = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
  263. $data['offlinePostage'] = $other['offlinePostage'];
  264. $vipId = UserLevel::getUserLevel($uid);
  265. $user = User::find($uid);
  266. if (isset($user['pwd'])) unset($user['pwd']);
  267. $user['vip'] = $vipId !== false ? true : false;
  268. if ($user['vip']) {
  269. $user['vip_id'] = $vipId;
  270. $user['discount'] = UserLevel::getUserLevelInfo($vipId, 'discount');
  271. }
  272. $data['userInfo'] = $user;
  273. $data['integralRatio'] = $other['integralRatio'];
  274. $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2;
  275. $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
  276. $data['system_store'] = ($res = \app\models\system\SystemStore::getStoreDispose()) ? $res : [];//门店信息
  277. return app('json')->successful($data);
  278. }
  279. /**
  280. * 计算订单金额
  281. * @param Request $request
  282. * @param $key
  283. * @return mixed
  284. * @throws \think\Exception
  285. * @throws \think\db\exception\DataNotFoundException
  286. * @throws \think\db\exception\ModelNotFoundException
  287. * @throws \think\exception\DbException
  288. */
  289. public function computedOrder($key)
  290. {
  291. $request = $this->request;
  292. $uid = input('uid', 0);
  293. if (!$key) return app('json')->fail('参数错误!');
  294. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  295. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  296. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
  297. 'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
  298. ['shipping_type', 1],
  299. ], $request, true);
  300. $payType = strtolower($payType);
  301. if ($bargainId) {
  302. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  303. if (!$bargainUserTableId)
  304. return app('json')->fail('砍价失败');
  305. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  306. if ($status == 3)
  307. return app('json')->fail('砍价已支付');
  308. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  309. }
  310. if ($pinkId) {
  311. $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
  312. if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
  313. return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $uid)]);
  314. }
  315. if (StorePink::getIsPinkUid($pinkId, $uid))
  316. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $uid)]);
  317. if (StoreOrder::getIsOrderPink($pinkId, $uid))
  318. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $uid)]);
  319. }
  320. $priceGroup = StoreOrder::cacheKeyCreateOrder($uid, $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
  321. if ($priceGroup)
  322. return app('json')->status('NONE', 'ok', $priceGroup);
  323. else
  324. return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  325. }
  326. /**
  327. * 订单创建
  328. * @param Request $request
  329. * @param $key
  330. * @return mixed
  331. * @throws \think\Exception
  332. * @throws \think\db\exception\DataNotFoundException
  333. * @throws \think\db\exception\ModelNotFoundException
  334. * @throws \think\exception\DbException
  335. */
  336. public function create($key)
  337. {
  338. $request = $this->request;
  339. $uid = input('uid', 0);
  340. if (!$key) return app('json')->fail('参数错误!');
  341. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  342. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  343. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId, $auth_code) = UtilService::postMore([
  344. 'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
  345. ['shipping_type', 1], ['real_name', '散户'], ['phone', '18700010001'], ['store_id', 0], ['auth_code', ''],
  346. ], $request, true);
  347. if (empty($real_name)) $real_name = '散户';
  348. if (empty($phone)) $phone = '18700010001';
  349. $payType = strtolower($payType);
  350. if ($bargainId) {
  351. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  352. if (!$bargainUserTableId)
  353. return app('json')->fail('砍价失败');
  354. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  355. if ($status == 3)
  356. return app('json')->fail('砍价已支付');
  357. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  358. }
  359. if ($pinkId) {
  360. $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
  361. if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
  362. return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $uid)]);
  363. }
  364. if (StorePink::getIsPinkUid($pinkId, $uid))
  365. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $uid)]);
  366. if (StoreOrder::getIsOrderPink($pinkId, $uid))
  367. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $uid)]);
  368. }
  369. $isChannel = 1;
  370. if ($from == 'weixin')
  371. $isChannel = 0;
  372. elseif ($from == 'weixinh5')
  373. $isChannel = 2;
  374. $order = StoreOrder::cacheKeyCreateOrder($uid, $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId);
  375. if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
  376. $orderId = $order['order_id'];
  377. $info = compact('orderId', 'key');
  378. if ($orderId) {
  379. event('OrderCreated', [$order]); //订单创建成功事件
  380. // event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
  381. switch ($payType) {
  382. case "weixin":
  383. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  384. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  385. $orderInfo = $orderInfo->toArray();
  386. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  387. //支付金额为0
  388. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  389. //创建订单jspay支付
  390. $payPriceStatus = StoreOrder::jsPayPrice($orderId, $uid, $formId);
  391. if ($payPriceStatus)//0元支付成功
  392. return app('json')->status('success', '微信支付成功', $info);
  393. else
  394. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  395. } else {
  396. try {
  397. $jsConfig = OrderRepository::barcodePay($orderId, $auth_code); //创建订单jspay
  398. } catch (\Exception $e) {
  399. return app('json')->status('pay_error', $e->getMessage(), $info);
  400. }
  401. $info['jsConfig'] = $jsConfig;
  402. if ($from == 'weixinh5') {
  403. return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
  404. } else {
  405. return app('json')->status('wechat_pay', '订单创建成功', $info);
  406. }
  407. }
  408. break;
  409. case 'yue':
  410. if (StoreOrder::yuePay($orderId, $uid, $formId)) {
  411. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  412. $this->verify($orderInfo['id']);
  413. return app('json')->status('success', '余额支付成功', $info);
  414. } else {
  415. $errorinfo = StoreOrder::getErrorInfo();
  416. if (is_array($errorinfo))
  417. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  418. else
  419. return app('json')->status('pay_error', $errorinfo);
  420. }
  421. break;
  422. case 'offline':
  423. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  424. $this->offline($orderInfo['id']);
  425. $this->verify($orderInfo['id']);
  426. return app('json')->status('success', '订单创建成功', $info);
  427. break;
  428. case 'jialie':
  429. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  430. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  431. $orderInfo = $orderInfo->toArray();
  432. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  433. $rs = OrderRepository::jialiePay($orderId, $auth_code); //支付结果
  434. if ($rs['ret_code'] == "00" && $rs['status'] == "2") {
  435. $this->verify($orderInfo['id']);
  436. StoreOrder::paySuccess($orderId, 'jialie');
  437. } elseif ($rs['ret_code'] == "00" && $rs['status'] == 1) {
  438. StoreOrder::edit(['jialie_do' => 1], $orderInfo['id']);
  439. } else {
  440. return app('json')->fail($rs['ret_msg']);
  441. }
  442. return app('json')->status('success', '订单创建成功', $info);
  443. break;
  444. }
  445. } else return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
  446. }
  447. public function verify($id)
  448. {
  449. StoreOrderModel::beginTrans();
  450. $orderInfo = StoreOrderModel::where('id', $id)->find();
  451. if ($orderInfo->combination_id && $orderInfo->pink_id) {
  452. $res = \app\admin\model\ump\StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count();
  453. if ($res) return Json::fail('拼团订单暂未成功无法核销!');
  454. }
  455. $orderInfo->status = 2;
  456. if ($orderInfo->save()) {
  457. OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
  458. StoreOrderStatus::setStatus($orderInfo->id, 'take_delivery', '已核销');
  459. StoreOrderModel::commitTrans();
  460. return true;
  461. } else {
  462. StoreOrderModel::rollbackTrans();
  463. return false;
  464. }
  465. }
  466. /**
  467. * 立即支付
  468. * @param $id
  469. */
  470. public function offline($id)
  471. {
  472. $res = StoreOrderModel::updateOffline($id);
  473. if ($res) {
  474. event('StoreProductOrderOffline', [$id]);
  475. StoreOrderStatus::setStatus($id, 'offline', '线下付款');
  476. return true;
  477. } else {
  478. return false;
  479. }
  480. }
  481. }