StoreOrderController.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. <?php
  2. namespace app\api\controller\order;
  3. use app\admin\model\system\{
  4. SystemAttachment, ShippingTemplates
  5. };
  6. use app\admin\model\user\User;
  7. use app\models\routine\RoutineFormId;
  8. use crmeb\repositories\OrderRepository;
  9. use app\models\store\{
  10. StoreBargainUser,
  11. StoreCart,
  12. StoreCoupon,
  13. StoreCouponIssue,
  14. StoreCouponUser,
  15. StoreOrder,
  16. StoreOrderBatch,
  17. StoreOrderCartInfo,
  18. StoreOrderStatus,
  19. StorePink,
  20. StoreProductReply,
  21. StoreSeckill
  22. };
  23. use app\models\system\SystemStore;
  24. use app\models\user\UserAddress;
  25. use app\models\user\UserLevel;
  26. use app\Request;
  27. use think\facade\{Cache};
  28. use crmeb\services\{
  29. CacheService,
  30. ExpressService,
  31. SystemConfigService,
  32. UtilService
  33. };
  34. /**
  35. * 订单类
  36. * Class StoreOrderController
  37. * @package app\api\controller\order
  38. */
  39. class StoreOrderController
  40. {
  41. /**
  42. * @api {post} /order/confirm 订单确认
  43. * @apiName PostOrderConfirm
  44. * @apiGroup User.Order
  45. *
  46. */
  47. public function confirm(Request $request)
  48. {
  49. // TODO: 运费模板只能选择 ID 为 1 的模板?
  50. $temp = ShippingTemplates::get(1);
  51. if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
  52. list($cartId) = UtilService::postMore(['cartId'], $request, true);
  53. if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品');
  54. // 查询当前购物车有效的商品
  55. $uid = $request->uid();
  56. $cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
  57. if (count($cartGroup['invalid'])) {
  58. return app('json')->fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
  59. }
  60. if (!$cartGroup['valid']) {
  61. return app('json')->fail('请提交购买的商品');
  62. }
  63. //
  64. $cartInfo = $cartGroup['valid'];
  65. $addr = UserAddress::getUserDefaultAddress($uid); //UserAddress::where('uid', $uid)->where('is_default', 1)->find();
  66. // 获取当前购物车中各项价格
  67. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
  68. if ($priceGroup === false) {
  69. return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
  70. }
  71. $other = [
  72. 'offlinePostage' => sys_config('offline_postage'), // 线下支付是否包邮
  73. 'integralRatio' => sys_config('integral_ratio') // 积分抵用比例
  74. ];
  75. $usableCoupons = []; // TIP 屏蔽优惠券 StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
  76. $usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
  77. // $cartIdA = explode(',', $cartId);
  78. $seckill_id = 0;
  79. $combination_id = 0;
  80. $bargain_id = 0;
  81. // TIP 屏蔽三个活动
  82. // if (count($cartIdA) == 1) {
  83. // $seckill_id = StoreCart::where('id', $cartId)->value('seckill_id');
  84. // $combination_id = StoreCart::where('id', $cartId)->value('combination_id');
  85. // $bargain_id = StoreCart::where('id', $cartId)->value('bargain_id');
  86. // }
  87. $data['deduction'] = $seckill_id || $combination_id || $bargain_id;
  88. $data['usableCoupon'] = $usableCoupon;
  89. $data['addressInfo'] = $addr; //UserAddress::getUserDefaultAddress($uid);
  90. $data['seckill_id'] = $seckill_id;
  91. $data['combination_id'] = $combination_id;
  92. $data['bargain_id'] = $bargain_id;
  93. $data['cartInfo'] = $cartInfo;
  94. $data['priceGroup'] = $priceGroup;
  95. $data['orderKey'] = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
  96. $data['offlinePostage'] = $other['offlinePostage'];
  97. $vipId = UserLevel::getUserLevel($uid);
  98. $user = $request->user();
  99. if (isset($user['pwd'])) unset($user['pwd']);
  100. $user['vip'] = $vipId !== false ? true : false;
  101. if ($user['vip']) {
  102. $user['vip_id'] = $vipId;
  103. $user['discount'] = UserLevel::getUserLevelInfo($vipId, 'discount');
  104. }
  105. $data['userInfo'] = $user;
  106. $data['integralRatio'] = $other['integralRatio'];
  107. $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2; // 线下支付
  108. $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
  109. $data['system_store'] = []; // TIP: 屏蔽门店信息 ($res = SystemStore::getStoreDispose()) ? $res : [];//门店信息
  110. return app('json')->successful($data);
  111. }
  112. /**
  113. * @api {post} /order/computed/:key 计算订单金额
  114. * @apiName PostOrderComputed
  115. * @apiGroup User.Order
  116. *
  117. */
  118. public function computedOrder(Request $request, $key)
  119. {
  120. // $key 就是 confirm 返回的 orderKey
  121. if (!$key) return app('json')->fail('参数错误!');
  122. // 是否已存在
  123. $uid = $request->uid();
  124. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  125. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  126. list($addressId, $couponId, $payType, $useIntegral, $mark,
  127. $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
  128. 'addressId',
  129. 'couponId',
  130. ['payType', 'yue'],
  131. ['useIntegral', 0],
  132. 'mark',
  133. ['combinationId', 0],
  134. ['pinkId', 0],
  135. ['seckill_id', 0],
  136. ['formId', ''],
  137. ['bargainId', ''],
  138. ['shipping_type', 1],
  139. ], $request, true);
  140. // weixin / yue
  141. $payType = strtolower($payType);
  142. if ($bargainId) {
  143. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  144. if (!$bargainUserTableId)
  145. return app('json')->fail('砍价失败');
  146. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  147. if ($status == 3)
  148. return app('json')->fail('砍价已支付');
  149. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  150. }
  151. if ($pinkId) {
  152. $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
  153. if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
  154. return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  155. }
  156. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  157. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  158. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  159. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  160. }
  161. $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
  162. $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
  163. // return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  164. if ($priceGroup)
  165. return app('json')->status('NONE', 'ok', $priceGroup);
  166. else
  167. return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  168. }
  169. /**
  170. * @api {post} /order/create/:key 订单创建
  171. * @apiName PostOrderCreate
  172. * @apiGroup User.Order
  173. *
  174. */
  175. public function create(Request $request, $key)
  176. {
  177. // 还是那个 $orderKey
  178. if (!$key) return app('json')->fail('参数错误!');
  179. // 订单是否已存在
  180. $uid = $request->uid();
  181. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  182. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  183. // 获得参数
  184. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
  185. 'addressId',
  186. 'couponId',
  187. 'payType',
  188. ['useIntegral', 0],
  189. 'mark',
  190. ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
  191. ['from', 'weixin'],
  192. ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
  193. ], $request, true);
  194. // weixin / yue
  195. $payType = strtolower($payType);
  196. if ($bargainId) {
  197. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  198. if (!$bargainUserTableId)
  199. return app('json')->fail('砍价失败');
  200. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  201. if ($status == 3)
  202. return app('json')->fail('砍价已支付');
  203. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  204. }
  205. if ($pinkId) {
  206. $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
  207. if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
  208. return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  209. }
  210. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  211. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  212. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  213. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  214. }
  215. $isChannel = 1; // 'routine'
  216. if ($from == 'weixin')
  217. $isChannel = 0;
  218. elseif ($from == 'weixinh5')
  219. $isChannel = 2;
  220. elseif ($from == 'app') {
  221. $isChannel = 3;
  222. }
  223. $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
  224. $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel,
  225. $shipping_type, $real_name, $phone, $storeId);
  226. if ($order === false) {
  227. return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
  228. }
  229. $orderId = $order['order_id'];
  230. $info = compact('orderId', 'key');
  231. if ($orderId) {
  232. event('OrderCreated', [$order]); //订单创建成功事件
  233. // event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
  234. switch ($payType) {
  235. case "weixin":
  236. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  237. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  238. $orderInfo = $orderInfo->toArray();
  239. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  240. //支付金额为0
  241. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  242. //创建订单jspay支付
  243. $payPriceStatus = StoreOrder::jsPayPrice($orderId, $uid, $formId);
  244. if ($payPriceStatus)//0元支付成功
  245. return app('json')->status('success', '微信支付成功', $info);
  246. else
  247. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  248. } else {
  249. try {
  250. if ($from == 'routine') {
  251. $jsConfig = OrderRepository::jsPay($orderId); //创建订单jspay
  252. } else if ($from == 'weixinh5') {
  253. $jsConfig = OrderRepository::h5Pay($orderId);
  254. } else if ($from == 'app') {
  255. $jsConfig = OrderRepository::wxAppPay($orderId);
  256. } else {
  257. $jsConfig = OrderRepository::wxPay($orderId);
  258. }
  259. } catch (\Exception $e) {
  260. errlog("weixin pay error:" . $e->getMessage());
  261. return app('json')->status('pay_error', $e->getMessage(), $info);
  262. }
  263. $info['jsConfig'] = $jsConfig;
  264. $status = 'wechat_pay'; // routine
  265. if ($from == 'weixinh5') {
  266. $status = 'wechat_h5_pay';
  267. } elseif ($from == 'app') {
  268. $status = 'wechat_app_pay';
  269. }
  270. return app('json')->status($status, '订单创建成功', $info);
  271. }
  272. break;
  273. case 'yue':
  274. if (StoreOrder::yuePay($orderId, $request->uid(), $formId))
  275. return app('json')->status('success', '余额支付成功', $info);
  276. else {
  277. $errorinfo = StoreOrder::getErrorInfo();
  278. if (is_array($errorinfo))
  279. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  280. else
  281. return app('json')->status('pay_error', $errorinfo);
  282. }
  283. break;
  284. case 'offline':
  285. return app('json')->status('success', '订单创建成功', $info);
  286. break;
  287. }
  288. } else { // !$orderId
  289. return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
  290. }
  291. }
  292. /**
  293. * @api {post} /order/v2/computed/:key 计算订单金额
  294. * @apiName PostOrderComputedV2
  295. * @apiGroup User.Order
  296. *
  297. */
  298. public function computedOrder_v2(Request $request, $key)
  299. {
  300. // $key 就是 confirm 返回的 orderKey
  301. if (!$key) return app('json')->fail('参数错误!');
  302. // 是否已存在
  303. $uid = $request->uid();
  304. if (StoreOrderBatch::be(['unique' => $key, 'uid' => $uid]))
  305. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  306. list($addressId, $couponId, $payType, $useIntegral, $mark,
  307. $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
  308. 'addressId',
  309. 'couponId',
  310. ['payType', 'yue'],
  311. ['useIntegral', 0],
  312. 'mark',
  313. ['combinationId', 0],
  314. ['pinkId', 0],
  315. ['seckill_id', 0],
  316. ['formId', ''],
  317. ['bargainId', ''],
  318. ['shipping_type', 1],
  319. ], $request, true);
  320. // weixin / yue
  321. $payType = strtolower($payType);
  322. if ($bargainId) {
  323. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  324. if (!$bargainUserTableId)
  325. return app('json')->fail('砍价失败');
  326. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  327. if ($status == 3)
  328. return app('json')->fail('砍价已支付');
  329. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  330. }
  331. if ($pinkId) {
  332. $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
  333. if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
  334. return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  335. }
  336. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  337. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  338. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  339. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  340. }
  341. $priceGroup = StoreOrderBatch::cacheKeyCreateOrderBatch($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
  342. $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
  343. // return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  344. if ($priceGroup)
  345. return app('json')->status('NONE', 'ok', $priceGroup);
  346. else
  347. return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  348. }
  349. /**
  350. * @api {post} /order/v2/create/:key 订单创建, 支持子订单版本
  351. * @apiName PostOrderCreateV2
  352. * @apiGroup User.Order
  353. *
  354. */
  355. public function create_v2(Request $request, $key)
  356. {
  357. // 还是那个 $orderKey
  358. if (!$key) {
  359. return app('json')->fail('参数错误!');
  360. }
  361. // 订单是否已存在
  362. $uid = $request->uid();
  363. if (StoreOrderBatch::be(['unique' => $key, 'uid' => $uid]))
  364. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  365. // 获得参数
  366. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
  367. 'addressId',
  368. 'couponId',
  369. 'payType',
  370. ['useIntegral', 0],
  371. 'mark',
  372. ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
  373. ['from', 'weixin'],
  374. ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
  375. ], $request, true);
  376. // weixin / yue
  377. $payType = strtolower($payType);
  378. if ($bargainId) {
  379. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  380. if (!$bargainUserTableId)
  381. return app('json')->fail('砍价失败');
  382. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  383. if ($status == 3)
  384. return app('json')->fail('砍价已支付');
  385. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  386. }
  387. if ($pinkId) {
  388. $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
  389. if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
  390. return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  391. }
  392. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  393. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  394. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  395. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  396. }
  397. $isChannel = 1; // 'routine'
  398. if ($from == 'weixin')
  399. $isChannel = 0;
  400. elseif ($from == 'weixinh5')
  401. $isChannel = 2;
  402. elseif ($from == 'app') {
  403. $isChannel = 3;
  404. }
  405. $porderId = StoreOrderBatch::cacheKeyCreateOrderBatch($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
  406. $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel,
  407. $shipping_type, $real_name, $phone, $storeId);
  408. if ($porderId === false) {
  409. return app('json')->fail(StoreOrderBatch::getErrorInfo('订单生成失败'));
  410. }
  411. $orderId = $porderId; // for compact
  412. $info = compact('orderId', 'key');
  413. if ($porderId) {
  414. event('BatchOrderCreated', [$porderId]); //订单创建成功事件
  415. // event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
  416. switch ($payType) {
  417. case "weixin":
  418. $subOrders = StoreOrderBatch::getAllSubOrders($porderId);
  419. if (!$subOrders) return app('json')->fail('支付订单不存在!');
  420. $fieldValues = StoreOrderBatch::sumFields($subOrders, ['paid','pay_price']);
  421. if ($fieldValues['paid']) {
  422. return app('json')->fail('支付已支付!');
  423. }
  424. //支付金额为0
  425. if (bcsub($fieldValues['pay_price'], 0, 2) <= 0) {
  426. //创建订单jspay支付
  427. $payPriceStatus = StoreOrderBatch::jsPayPriceBatch($porderId, $uid, $formId);
  428. if ($payPriceStatus)//0元支付成功
  429. return app('json')->status('success', '微信支付成功', $info);
  430. else
  431. return app('json')->status('pay_error', StoreOrderBatch::getErrorInfo());
  432. } else {
  433. try {
  434. if ($from == 'routine') {
  435. $jsConfig = OrderRepository::jsPayBatch($porderId); //创建订单jspay
  436. } else if ($from == 'weixinh5') {
  437. $jsConfig = OrderRepository::h5PayBatch($porderId);
  438. } elseif ($from == 'app') {
  439. $jsConfig = OrderRepository::wxAppPayBatch($porderId);
  440. } else {
  441. $jsConfig = OrderRepository::wxPayBatch($porderId);
  442. }
  443. } catch (\Exception $e) {
  444. errlog("weixin pay error:" . $e->getMessage());
  445. return app('json')->status('pay_error', $e->getMessage(), $info);
  446. }
  447. $info['jsConfig'] = $jsConfig;
  448. $status = 'wechat_pay'; // routine
  449. if ($from == 'weixinh5') {
  450. $status = 'wechat_h5_pay';
  451. } elseif ($from == 'app') {
  452. $status = 'wechat_app_pay';
  453. }
  454. return app('json')->status($status, '订单创建成功', $info);
  455. }
  456. break;
  457. case 'yue':
  458. if (StoreOrderBatch::yuePayBatch($porderId, $request->uid(), $formId))
  459. return app('json')->status('success', '余额支付成功', $info);
  460. else {
  461. $errorinfo = StoreOrderBatch::getErrorInfo();
  462. if (is_array($errorinfo))
  463. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  464. else
  465. return app('json')->status('pay_error', $errorinfo);
  466. }
  467. break;
  468. case 'offline':
  469. return app('json')->status('success', '订单创建成功', $info);
  470. break;
  471. }
  472. } else { // !$orderId
  473. return app('json')->fail(StoreOrderBatch::getErrorInfo('订单生成失败!'));
  474. }
  475. }
  476. /**
  477. * @api {post} /order/again 订单 再次下单
  478. * @apiName PostOrderAgain
  479. * @apiGroup User.Order
  480. *
  481. */
  482. public function again(Request $request)
  483. {
  484. list($uni) = UtilService::postMore([
  485. ['uni', ''],
  486. ], $request, true);
  487. if (!$uni) return app('json')->fail('参数错误!');
  488. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  489. if (!$order) return app('json')->fail('订单不存在!');
  490. $order = StoreOrder::tidyOrder($order, true);
  491. $res = [];
  492. foreach ($order['cartInfo'] as $v) {
  493. if ($v['combination_id']) return app('json')->fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
  494. else if ($v['bargain_id']) return app('json')->fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
  495. else if ($v['seckill_id']) return app('json')->ail('秒杀产品不能再来一单,请在秒杀产品内自行下单!');
  496. else $res[] = StoreCart::setCart($request->uid(), $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
  497. }
  498. $cateId = [];
  499. foreach ($res as $v) {
  500. if (!$v) return app('json')->fail('再来一单失败,请重新下单!');
  501. $cateId[] = $v['id'];
  502. }
  503. event('OrderCreateAgain', implode(',', $cateId));
  504. return app('json')->successful('ok', ['cateId' => implode(',', $cateId)]);
  505. }
  506. /**
  507. * @api {post} /order/pay 订单支付
  508. * @apiName PostOrderPay
  509. * @apiGroup User.Order
  510. *
  511. */
  512. public function pay(Request $request)
  513. {
  514. list($uni, $paytype, $from) = UtilService::postMore([
  515. ['uni', ''],
  516. ['paytype', 'weixin'],
  517. ['from', 'weixin']
  518. ], $request, true);
  519. if (!$uni) return app('json')->fail('参数错误!');
  520. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  521. if (!$order)
  522. return app('json')->fail('订单不存在!');
  523. if ($order['paid'])
  524. return app('json')->fail('该订单已支付!');
  525. if ($order['pink_id']) {
  526. $cache_pink = Cache::get(md5('store_pink_' . $order['pink_id']));
  527. if (StorePink::isPinkStatus($order['pink_id']) || ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0)) {
  528. return app('json')->fail('该订单已失效!');
  529. }
  530. }
  531. if ($from == 'weixin') {//0
  532. if (in_array($order->is_channel, [1, 2, 3]))
  533. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  534. }
  535. if ($from == 'weixinh5') {//2
  536. if (in_array($order->is_channel, [0, 1, 3]))
  537. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  538. }
  539. if ($from == 'routine') {//1
  540. if (in_array($order->is_channel, [0, 2, 3]))
  541. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  542. }
  543. if ($from == 'app') {
  544. if (in_array($order->is_channel, [0, 1, 2])) {
  545. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  546. }
  547. }
  548. $order['pay_type'] = $paytype; //重新支付选择支付方式
  549. switch ($order['pay_type']) {
  550. case 'weixin':
  551. try {
  552. if ($from == 'routine') {
  553. $jsConfig = OrderRepository::jsPay($order); //订单列表发起支付
  554. } else if ($from == 'weixinh5') {
  555. $jsConfig = OrderRepository::h5Pay($order);
  556. } else if ($from == 'app') {
  557. $jsConfig = OrderRepository::wxAppPay($order);
  558. } else {
  559. $jsConfig = OrderRepository::wxPay($order);
  560. }
  561. } catch (\Exception $e) {
  562. errlog('weixin pay error:' . $e->getMessage());
  563. return app('json')->fail($e->getMessage());
  564. }
  565. // return app('json')->status($paytype . '_' . $from, ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  566. $status = 'wechat_pay'; // routine
  567. if ($from == 'weixinh5') {
  568. $status = 'wechat_h5_pay';
  569. } elseif ($from == 'app') {
  570. $status = 'wechat_app_pay';
  571. }
  572. return app('json')->status($status, ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  573. // if ($from == 'weixinh5') {
  574. // return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  575. // } else {
  576. // return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  577. // }
  578. break;
  579. case 'yue':
  580. if (StoreOrder::yuePay($order['order_id'], $request->uid()))
  581. return app('json')->status('success', '余额支付成功');
  582. else {
  583. $error = StoreOrder::getErrorInfo();
  584. return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
  585. }
  586. break;
  587. case 'offline':
  588. StoreOrder::createOrderTemplate($order);
  589. if (StoreOrder::setOrderTypePayOffline($order['order_id']))
  590. return app('json')->status('success', '订单创建成功');
  591. else
  592. return app('json')->status('success', '支付失败');
  593. break;
  594. case 'alipay':
  595. break;
  596. }
  597. return app('json')->fail('支付方式错误');
  598. }
  599. /**
  600. * @api {get} /order/list 订单列表
  601. * @apiName GetOrderList
  602. * @apiGroup User.Order
  603. *
  604. */
  605. public function lst(Request $request)
  606. {
  607. list($type, $page, $limit, $search) = UtilService::getMore([
  608. ['type', ''],
  609. ['page', 0],
  610. ['limit', ''],
  611. ['search', ''],
  612. ], $request, true);
  613. return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
  614. }
  615. /**
  616. * @api {get} /order/v2/detail/:uni 订单详情 v2
  617. * @apiName GetOrderDetailsV2
  618. * @apiGroup User.Order
  619. *
  620. * @apiDescription 订单支持子订单之后,订单详情协议传过来的 $uni 有可能是子订单的,也有可能是主订单的
  621. *
  622. */
  623. public function detail_v2(Request $request, $uni)
  624. {
  625. if (!strlen(trim($uni))) return app('json')->fail('参数错误');
  626. $uid = $request->uid();
  627. $first4 = mb_substr($uni, 0, 4);
  628. if ($first4 == 'wxcn') {
  629. $porder = StoreOrderBatch::where('porder_id', $uni)->where('uid', $uid)->find();
  630. if (!$porder) {
  631. return app('json')->fail('订单不存在');
  632. }
  633. $porder = $porder->toArray();
  634. $subOrders = StoreOrderBatch::getAllSubOrders($porder['porder_id']);
  635. if (!$subOrders) {
  636. return app('json')->fail('订单不存在');
  637. }
  638. $order = $this->__get_order_details($uid, $subOrders[0]['order_id']);
  639. if (!$order) {
  640. return app('json')->fail('订单不存在');
  641. }
  642. $order['order_id'] = $porder['porder_id'];
  643. $order['pay_price'] = $porder['total_price'];
  644. return app('json')->successful('ok', $order);
  645. } else {
  646. return $this->detail($request, $uni);
  647. }
  648. }
  649. /**
  650. * @api {get} /order/detail/:uni 订单详情
  651. * @apiName GetOrderDetails
  652. * @apiGroup User.Order
  653. *
  654. */
  655. public function detail(Request $request, $uni)
  656. {
  657. $order = $this->__get_order_details($request->uid(), $uni);
  658. if (!$order) {
  659. return app('json')->fail('订单不存在');
  660. }
  661. return app('json')->successful('ok', $order);
  662. }
  663. public function __get_order_details($uid, $uni)
  664. {
  665. $order = StoreOrder::getUserOrderDetail($uid, $uni);
  666. if (!$order) {
  667. return false;
  668. }
  669. $order = $order->toArray();
  670. //是否开启门店自提
  671. $store_self_mention = sys_config('store_self_mention');
  672. //关闭门店自提后 订单隐藏门店信息
  673. if ($store_self_mention == 0) $order['shipping_type'] = 1;
  674. if ($order['verify_code']) {
  675. $verify_code = $order['verify_code'];
  676. $verify[] = substr($verify_code, 0, 4);
  677. $verify[] = substr($verify_code, 4, 4);
  678. $verify[] = substr($verify_code, 8);
  679. $order['_verify_code'] = implode(' ', $verify);
  680. }
  681. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  682. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  683. $order['system_store'] = SystemStore::getStoreDispose($order['store_id']);
  684. if ($order['shipping_type'] === 2 && $order['verify_code']) {
  685. $name = $order['verify_code'] . '.jpg';
  686. $imageInfo = SystemAttachment::getInfo($name, 'name');
  687. $siteUrl = sys_config('site_url');
  688. if (!$imageInfo) {
  689. $imageInfo = UtilService::getQRCodePath($order['verify_code'], $name);
  690. if (is_array($imageInfo)) {
  691. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  692. $url = $imageInfo['dir'];
  693. } else
  694. $url = '';
  695. } else $url = $imageInfo['att_dir'];
  696. if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  697. $order['code'] = $url;
  698. }
  699. $order['mapKey'] = sys_config('tengxun_map_key');
  700. return StoreOrder::tidyOrder($order, true, true);
  701. }
  702. /**
  703. * @api {post} /order/del 订单删除
  704. * @apiName PostOrderDel
  705. * @apiGroup User.Order
  706. *
  707. */
  708. public function del(Request $request)
  709. {
  710. list($uni) = UtilService::postMore([
  711. ['uni', ''],
  712. ], $request, true);
  713. if (!$uni) return app('json')->fail('参数错误!');
  714. $res = StoreOrder::removeOrder($uni, $request->uid());
  715. if ($res)
  716. return app('json')->successful();
  717. else
  718. return app('json')->fail(StoreOrder::getErrorInfo());
  719. }
  720. /**
  721. * @api {post} /order/take 订单收货
  722. * @apiName PostOrderTake
  723. * @apiGroup User.Order
  724. *
  725. */
  726. public function take(Request $request)
  727. {
  728. list($uni) = UtilService::postMore([
  729. ['uni', ''],
  730. ], $request, true);
  731. if (!$uni) return app('json')->fail('参数错误!');
  732. $res = StoreOrder::takeOrder($uni, $request->uid());
  733. if ($res) {
  734. $order_info = StoreOrder::where('order_id', $uni)->find();
  735. $gain_integral = intval($order_info['gain_integral']);
  736. $gain_coupon = StoreCouponIssue::alias('a')
  737. ->join('store_coupon b', 'a.cid = b.id')
  738. ->where('a.status', 1)
  739. ->where('a.is_full_give', 1)
  740. ->where('a.is_del', 0)
  741. ->where('a.full_reduction', '<=', $order_info['total_price'])
  742. ->sum('b.coupon_price');
  743. return app('json')->successful(['gain_integral' => $gain_integral, 'gain_coupon' => $gain_coupon]);
  744. } else
  745. return app('json')->fail(StoreOrder::getErrorInfo());
  746. }
  747. /**
  748. * @api {get} /order/express/:uni 订单 查看物流
  749. * @apiName GetOrderExpress
  750. * @apiGroup User.Order
  751. *
  752. */
  753. public function express(Request $request, $uni)
  754. {
  755. if (!$uni || !($order = StoreOrder::getUserOrderDetail($request->uid(), $uni))) return app('json')->fail('查询订单不存在!');
  756. if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return app('json')->fail('该订单不存在快递单号!');
  757. $cacheName = $uni . $order['delivery_id'];
  758. $result = CacheService::get($cacheName);
  759. if (!$result) {
  760. try {
  761. $result = ExpressService::query($order['delivery_id'], $order['delivery_name']);
  762. } catch (\Throwable $e) {
  763. $result = [];
  764. }
  765. if (is_array($result) && (isset($result['result']) || isset($result['content']))) {
  766. $cacheTime = 1200;
  767. if(isset($result['content'])){
  768. $result['result'] = $result['content'];
  769. unset($result['content']);
  770. }
  771. }else
  772. $cacheTime = 1800;
  773. CacheService::set($cacheName, $result, $cacheTime);
  774. }
  775. $orderInfo = [];
  776. $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('cart_info', 'unique') ?? [];
  777. $info = [];
  778. $cartNew = [];
  779. foreach ($cartInfo as $k => $cart) {
  780. $cart = json_decode($cart, true);
  781. $cartNew['cart_num'] = $cart['cart_num'];
  782. $cartNew['truePrice'] = $cart['truePrice'];
  783. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  784. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  785. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  786. array_push($info, $cartNew);
  787. unset($cart);
  788. }
  789. $orderInfo['delivery_id'] = $order['delivery_id'];
  790. $orderInfo['delivery_name'] = $order['delivery_name'];
  791. $orderInfo['delivery_type'] = $order['delivery_type'];
  792. $orderInfo['cartInfo'] = $info;
  793. return app('json')->successful(['order' => $orderInfo, 'express' => $result ? $result : []]);
  794. }
  795. /**
  796. * @api {post} /order/comment 订单评价
  797. * @apiName PostOrderComment
  798. * @apiGroup User.Order
  799. *
  800. */
  801. public function comment(Request $request)
  802. {
  803. $group = UtilService::postMore([
  804. ['unique', ''], ['comment', ''], ['pics', ''], ['product_score', 5], ['service_score', 5]
  805. ], $request);
  806. $unique = $group['unique'];
  807. unset($group['unique']);
  808. if (!$unique) return app('json')->fail('参数错误!');
  809. $cartInfo = StoreOrderCartInfo::where('unique', $unique)->find();
  810. $uid = $request->uid();
  811. $user_info = User::get($uid);
  812. $group['nickname'] = $user_info['nickname'];
  813. $group['avatar'] = $user_info['avatar'];
  814. if (!$cartInfo) return app('json')->fail('评价产品不存在!');
  815. $orderUid = StoreOrder::getOrderInfo($cartInfo['oid'], 'uid')['uid'];
  816. if ($uid != $orderUid) {
  817. return app('json')->fail('评价产品不存在!');
  818. }
  819. if (StoreProductReply::be(['oid' => $cartInfo['oid'], 'unique' => $unique]))
  820. return app('json')->fail('该产品已评价!');
  821. $group['comment'] = htmlspecialchars(trim($group['comment']));
  822. if ($group['product_score'] < 1) return app('json')->fail('请为产品评分');
  823. else if ($group['service_score'] < 1) return app('json')->fail('请为商家服务评分');
  824. //
  825. $cartInfo['cart_info'] = json_decode($cartInfo['cart_info'], true);
  826. if ($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
  827. else if ($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
  828. else if ($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
  829. else $productId = $cartInfo['product_id'];
  830. if ($group['pics']) {
  831. $group['pics'] = json_encode(is_array($group['pics']) ? $group['pics'] : explode(',', $group['pics']));
  832. } else {
  833. $group['pics'] = '';
  834. }
  835. $group = array_merge($group, [
  836. 'uid' => $uid,
  837. 'oid' => $cartInfo['oid'],
  838. 'unique' => $unique,
  839. 'product_id' => $productId,
  840. 'add_time' => time(),
  841. 'reply_type' => 'product'
  842. ]);
  843. StoreProductReply::beginTrans();
  844. $res = StoreProductReply::reply($group, 'product');
  845. if (!$res) {
  846. StoreProductReply::rollbackTrans();
  847. return app('json')->fail('评价失败!');
  848. }
  849. try {
  850. StoreOrder::checkOrderOver($cartInfo['oid']);
  851. } catch (\Exception $e) {
  852. StoreProductReply::rollbackTrans();
  853. return app('json')->fail($e->getMessage());
  854. }
  855. StoreProductReply::commitTrans();
  856. event('UserCommented', $res);
  857. event('AdminNewPush');
  858. return app('json')->successful();
  859. }
  860. /**
  861. * @api {get} /order/data 订单统计数据
  862. * @apiName GetOrderData
  863. * @apiGroup User.Order
  864. *
  865. */
  866. public function data(Request $request)
  867. {
  868. return app('json')->successful(StoreOrder::getOrderData($request->uid()));
  869. }
  870. /**
  871. * @api {get} /order/refund/reason 订单退款理由
  872. * @apiName GetOrderRefundReason
  873. * @apiGroup User.Order
  874. *
  875. */
  876. public function refund_reason()
  877. {
  878. $reason = sys_config('stor_reason') ?: [];//退款理由
  879. $reason = str_replace("\r\n", "\n", $reason);//防止不兼容
  880. $reason = explode("\n", $reason);
  881. return app('json')->successful($reason);
  882. }
  883. /**
  884. * @api {post} /order/refund/verify 订单退款审核
  885. * @apiName PostOrderRefundVerify
  886. * @apiGroup User.Order
  887. *
  888. */
  889. public function refund_verify(Request $request)
  890. {
  891. $data = UtilService::postMore([
  892. ['text', ''],
  893. ['refund_reason_wap_img', ''],
  894. ['refund_reason_wap_explain', ''],
  895. ['uni', '']
  896. ], $request);
  897. $uni = $data['uni'];
  898. unset($data['uni']);
  899. if ($data['refund_reason_wap_img']) $data['refund_reason_wap_img'] = explode(',', $data['refund_reason_wap_img']);
  900. if (!$uni || $data['text'] == '') return app('json')->fail('参数错误!');
  901. $res = StoreOrder::orderApplyRefund($uni, $request->uid(), $data['text'], $data['refund_reason_wap_explain'], $data['refund_reason_wap_img']);
  902. if ($res)
  903. return app('json')->successful('提交申请成功');
  904. else
  905. return app('json')->fail(StoreOrder::getErrorInfo());
  906. }
  907. /**
  908. * 订单取消 未支付的订单回退积分,回退优惠券,回退库存
  909. * @param Request $request
  910. * @return mixed
  911. * @throws \think\db\exception\DataNotFoundException
  912. * @throws \think\db\exception\ModelNotFoundException
  913. * @throws \think\exception\DbException
  914. */
  915. public function cancel(Request $request)
  916. {
  917. list($id) = UtilService::postMore([['id', 0]], $request, true);
  918. if (!$id) return app('json')->fail('参数错误');
  919. if (StoreOrder::cancelOrder($id, $request->uid()))
  920. return app('json')->successful('取消订单成功');
  921. return app('json')->fail(StoreOrder::getErrorInfo('取消订单失败'));
  922. }
  923. /**
  924. * @api {post} /order/product 订单产品信息
  925. * @apiName PostOrderProduct
  926. * @apiGroup User.Order
  927. *
  928. */
  929. public function product(Request $request)
  930. {
  931. list($unique) = UtilService::postMore([['unique', '']], $request, true);
  932. if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return app('json')->fail('评价产品不存在!');
  933. $cartInfo = $cartInfo->toArray();
  934. $cartProduct = [];
  935. $cartProduct['cart_num'] = $cartInfo['cart_info']['cart_num'];
  936. $cartProduct['productInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['image']) ? $cartInfo['cart_info']['productInfo']['image'] : '';
  937. $cartProduct['productInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['price']) ? $cartInfo['cart_info']['productInfo']['price'] : 0;
  938. $cartProduct['productInfo']['store_name'] = isset($cartInfo['cart_info']['productInfo']['store_name']) ? $cartInfo['cart_info']['productInfo']['store_name'] : '';
  939. if (isset($cartInfo['cart_info']['productInfo']['attrInfo'])) {
  940. $cartProduct['productInfo']['attrInfo']['product_id'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['product_id']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['product_id'] : '';
  941. $cartProduct['productInfo']['attrInfo']['suk'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['suk']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['suk'] : '';
  942. $cartProduct['productInfo']['attrInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['price']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['price'] : '';
  943. $cartProduct['productInfo']['attrInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['image']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['image'] : '';
  944. }
  945. $cartProduct['product_id'] = isset($cartInfo['cart_info']['product_id']) ? $cartInfo['cart_info']['product_id'] : 0;
  946. $cartProduct['combination_id'] = isset($cartInfo['cart_info']['combination_id']) ? $cartInfo['cart_info']['combination_id'] : 0;
  947. $cartProduct['seckill_id'] = isset($cartInfo['cart_info']['seckill_id']) ? $cartInfo['cart_info']['seckill_id'] : 0;
  948. $cartProduct['bargain_id'] = isset($cartInfo['cart_info']['bargain_id']) ? $cartInfo['cart_info']['bargain_id'] : 0;
  949. $cartProduct['order_id'] = StoreOrder::where('id', $cartInfo['oid'])->value('order_id');
  950. return app('json')->successful($cartProduct);
  951. }
  952. /**
  953. * @api {get} /order/nopay 首页获取未支付订单
  954. * @apiName GetOrderNopay
  955. * @apiGroup User.Order
  956. *
  957. */
  958. public function get_noPay(Request $request)
  959. {
  960. return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), 0, 0, 0, ''));
  961. }
  962. }