Placeorder.php 24 KB

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