StoreOrderController.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. <<<<<<< HEAD
  2. <?php
  3. namespace app\api\controller\order;
  4. use app\api\controller\Gmdemo;
  5. use app\admin\model\system\{
  6. SystemAttachment, ShippingTemplates
  7. };
  8. use app\admin\model\user\User;
  9. use app\models\routine\RoutineFormId;
  10. use crmeb\repositories\OrderRepository;
  11. use app\models\store\{
  12. StoreBargainUser,
  13. StoreCart,
  14. StoreCoupon,
  15. StoreCouponIssue,
  16. StoreCouponUser,
  17. StoreOrder,
  18. StoreOrderCartInfo,
  19. StoreOrderStatus,
  20. StorePink,
  21. StoreProductReply
  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 crmeb\services\{
  28. CacheService,
  29. ExpressService,
  30. SystemConfigService,
  31. UtilService
  32. };
  33. /**
  34. * 订单类
  35. * Class StoreOrderController
  36. * @package app\api\controller\order
  37. */
  38. class StoreOrderController
  39. {
  40. /**
  41. * 订单确认
  42. * @param Request $request
  43. * @return mixed
  44. */
  45. public function confirm(Request $request)
  46. {
  47. $temp = ShippingTemplates::get(1);
  48. if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
  49. list($cartId) = UtilService::postMore(['cartId'], $request, true);
  50. if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品');
  51. $uid = $request->uid();
  52. $cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
  53. if (count($cartGroup['invalid'])) return app('json')->fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
  54. if (!$cartGroup['valid']) return app('json')->fail('请提交购买的商品');
  55. $cartInfo = $cartGroup['valid'];
  56. $addr = UserAddress::where('uid', $uid)->where('is_default', 1)->find();
  57. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
  58. if ($priceGroup === false) {
  59. return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
  60. }
  61. $other = [
  62. 'offlinePostage' => sys_config('offline_postage'),
  63. 'integralRatio' => sys_config('integral_ratio')
  64. ];
  65. $usableCoupons = StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
  66. $usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
  67. $cartIdA = explode(',', $cartId);
  68. $seckill_id = 0;
  69. $combination_id = 0;
  70. $bargain_id = 0;
  71. if (count($cartIdA) == 1) {
  72. $seckill_id = StoreCart::where('id', $cartId)->value('seckill_id');
  73. $combination_id = StoreCart::where('id', $cartId)->value('combination_id');
  74. $bargain_id = StoreCart::where('id', $cartId)->value('bargain_id');
  75. }
  76. $data['deduction'] = $seckill_id || $combination_id || $bargain_id;
  77. $data['usableCoupon'] = $usableCoupon;
  78. $data['addressInfo'] = UserAddress::getUserDefaultAddress($uid);
  79. $data['seckill_id'] = $seckill_id;
  80. $data['combination_id'] = $combination_id;
  81. $data['bargain_id'] = $bargain_id;
  82. $data['cartInfo'] = $cartInfo;
  83. $data['priceGroup'] = $priceGroup;
  84. $data['orderKey'] = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
  85. $data['offlinePostage'] = $other['offlinePostage'];
  86. $vipId = UserLevel::getUserLevel($uid);
  87. $user = $request->user();
  88. if (isset($user['pwd'])) unset($user['pwd']);
  89. $user['vip'] = $vipId !== false ? true : false;
  90. if ($user['vip']) {
  91. $user['vip_id'] = $vipId;
  92. $user['discount'] = UserLevel::getUserLevelInfo($vipId, 'discount');
  93. }
  94. $data['userInfo'] = $user;
  95. $data['integralRatio'] = $other['integralRatio'];
  96. $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2;
  97. $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
  98. $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];//门店信息
  99. return app('json')->successful($data);
  100. }
  101. /**
  102. * 计算订单金额
  103. * @param Request $request
  104. * @param $key
  105. * @return mixed
  106. * @throws \think\Exception
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. */
  111. public function computedOrder(Request $request, $key)
  112. {
  113. // $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
  114. if (!$key) return app('json')->fail('参数错误!');
  115. $uid = $request->uid();
  116. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  117. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  118. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
  119. 'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
  120. ['shipping_type', 1],
  121. ], $request, true);
  122. $payType = strtolower($payType);
  123. if ($bargainId) {
  124. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  125. if (!$bargainUserTableId)
  126. return app('json')->fail('砍价失败');
  127. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  128. if ($status == 3)
  129. return app('json')->fail('砍价已支付');
  130. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  131. }
  132. if ($pinkId) {
  133. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  134. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  135. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  136. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  137. }
  138. $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
  139. if ($priceGroup)
  140. return app('json')->status('NONE', 'ok', $priceGroup);
  141. else
  142. return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  143. }
  144. /**
  145. * 订单创建
  146. * @param Request $request
  147. * @param $key
  148. * @return mixed
  149. * @throws \think\Exception
  150. * @throws \think\db\exception\DataNotFoundException
  151. * @throws \think\db\exception\ModelNotFoundException
  152. * @throws \think\exception\DbException
  153. */
  154. public function create(Request $request, $key)
  155. {
  156. if (!$key) return app('json')->fail('参数错误!');
  157. $uid = $request->uid();
  158. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  159. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  160. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
  161. 'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
  162. ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
  163. ], $request, true);
  164. $payType = strtolower($payType);
  165. if ($bargainId) {
  166. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  167. if (!$bargainUserTableId)
  168. return app('json')->fail('砍价失败');
  169. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  170. if ($status == 3)
  171. return app('json')->fail('砍价已支付');
  172. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  173. }
  174. if ($pinkId) {
  175. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  176. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  177. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  178. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  179. }
  180. $isChannel = 1;
  181. if ($from == 'weixin')
  182. $isChannel = 0;
  183. elseif ($from == 'weixinh5')
  184. $isChannel = 2;
  185. $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId);
  186. if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
  187. $orderId = $order['order_id'];
  188. $info = compact('orderId', 'key');
  189. if ($orderId) {
  190. event('OrderCreated', [$order]); //订单创建成功事件
  191. event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
  192. switch ($payType) {
  193. case "weixin":
  194. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  195. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  196. $orderInfo = $orderInfo->toArray();
  197. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  198. //支付金额为0
  199. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  200. //创建订单jspay支付
  201. $payPriceStatus = StoreOrder::jsPayPrice($orderId, $uid, $formId);
  202. if ($payPriceStatus)//0元支付成功
  203. return app('json')->status('success', '微信支付成功', $info);
  204. else
  205. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  206. } else {
  207. try {
  208. if ($from == 'routine') {
  209. $jsConfig = OrderRepository::jsPay($orderId); //创建订单jspay
  210. } else if ($from == 'weixinh5') {
  211. $jsConfig = OrderRepository::h5Pay($orderId);
  212. } else {
  213. $jsConfig = OrderRepository::wxPay($orderId);
  214. }
  215. } catch (\Exception $e) {
  216. return app('json')->status('pay_error', $e->getMessage(), $info);
  217. }
  218. $info['jsConfig'] = $jsConfig;
  219. if ($from == 'weixinh5') {
  220. return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
  221. } else {
  222. return app('json')->status('wechat_pay', '订单创建成功', $info);
  223. }
  224. }
  225. break;
  226. case "ali":
  227. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  228. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  229. $orderInfo = $orderInfo->toArray();
  230. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  231. //支付金额为0
  232. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  233. //创建订单jspay支付
  234. $payPriceStatus = StoreOrder::jsPayPrice($orderId, $request->uid());
  235. if ($payPriceStatus)//0元支付成功
  236. return app('json')->status('success', '支付成功');
  237. else
  238. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  239. } else {
  240. try {
  241. $jsConfig = OrderRepository::aliPay($orderId); //创建订单jspay
  242. } catch (\Exception $e) {
  243. return app('json')->status('pay_error', $e->getMessage());
  244. }
  245. $info['jsConfig'] = $jsConfig;
  246. return app('json')->status('ali_pay', '订单创建成功', $info);
  247. }
  248. break;
  249. case 'yue':
  250. if (StoreOrder::yuePay($orderId, $request->uid(), $formId))
  251. return app('json')->status('success', '余额支付成功', $info);
  252. else {
  253. $errorinfo = StoreOrder::getErrorInfo();
  254. if (is_array($errorinfo))
  255. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  256. else
  257. return app('json')->status('pay_error', $errorinfo);
  258. }
  259. break;
  260. case 'offline':
  261. return app('json')->status('success', '订单创建成功', $info);
  262. break;
  263. }
  264. } else return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
  265. }
  266. /**
  267. * 订单 再次下单
  268. * @param Request $request
  269. * @return mixed
  270. */
  271. public function again(Request $request)
  272. {
  273. list($uni) = UtilService::postMore([
  274. ['uni', ''],
  275. ], $request, true);
  276. if (!$uni) return app('json')->fail('参数错误!');
  277. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  278. if (!$order) return app('json')->fail('订单不存在!');
  279. $order = StoreOrder::tidyOrder($order, true);
  280. $res = [];
  281. foreach ($order['cartInfo'] as $v) {
  282. if ($v['combination_id']) return app('json')->fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
  283. else if ($v['bargain_id']) return app('json')->fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
  284. else if ($v['seckill_id']) return app('json')->ail('秒杀产品不能再来一单,请在秒杀产品内自行下单!');
  285. else $res[] = StoreCart::setCart($request->uid(), $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
  286. }
  287. $cateId = [];
  288. foreach ($res as $v) {
  289. if (!$v) return app('json')->fail('再来一单失败,请重新下单!');
  290. $cateId[] = $v['id'];
  291. }
  292. event('OrderCreateAgain', implode(',', $cateId));
  293. return app('json')->successful('ok', ['cateId' => implode(',', $cateId)]);
  294. }
  295. /**
  296. * 订单支付
  297. * @param Request $request
  298. * @return mixed
  299. */
  300. public function pay(Request $request)
  301. {
  302. list($uni, $paytype, $from) = UtilService::postMore([
  303. ['uni', ''],
  304. ['paytype', 'weixin'],
  305. ['from', 'weixin']
  306. ], $request, true);
  307. if (!$uni) return app('json')->fail('参数错误!');
  308. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  309. if (!$order)
  310. return app('json')->fail('订单不存在!');
  311. if ($order['paid'])
  312. return app('json')->fail('该订单已支付!');
  313. if ($order['pink_id']) if (StorePink::isPinkStatus($order['pink_id']))
  314. return app('json')->fail('该订单已失效!');
  315. if ($from == 'weixin') {//0
  316. if (in_array($order->is_channel, [1, 2]))
  317. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  318. }
  319. if ($from == 'weixinh5') {//2
  320. if (in_array($order->is_channel, [0, 1]))
  321. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  322. }
  323. if ($from == 'routine') {//1
  324. if (in_array($order->is_channel, [0, 2]))
  325. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  326. }
  327. $order['pay_type'] = $paytype; //重新支付选择支付方式
  328. switch ($order['pay_type']) {
  329. case 'weixin':
  330. try {
  331. if ($from == 'routine') {
  332. $jsConfig = OrderRepository::jsPay($order); //订单列表发起支付
  333. } else if ($from == 'weixinh5') {
  334. $jsConfig = OrderRepository::h5Pay($order);
  335. } else {
  336. $jsConfig = OrderRepository::wxPay($order);
  337. }
  338. } catch (\Exception $e) {
  339. return app('json')->fail($e->getMessage());
  340. }
  341. if ($from == 'weixinh5') {
  342. return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  343. } else {
  344. return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  345. }
  346. break;
  347. case 'yue':
  348. if (StoreOrder::yuePay($order['order_id'], $request->uid()))
  349. return app('json')->status('success', '余额支付成功');
  350. else {
  351. $error = StoreOrder::getErrorInfo();
  352. return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
  353. }
  354. break;
  355. case 'ztpay':
  356. $gm = new Gmdemo();
  357. $data = [
  358. 'mechNo' => 123456,// 商户号
  359. 'inetNo' => $order['order_id'],//订单号
  360. 'sndTmstmp' => date('YmdHis', time()),
  361. 'pdDsc' => '=商品购买',
  362. 'pymntAmt' => $order['pay_price'] * 100, // 交 易 单 位 为 分
  363. 'ccy' => 156,
  364. 'channelCode' => ''//渠道号
  365. ];
  366. $res = $gm->scanPaymentCode($data);
  367. halt($res);
  368. case 'offline':
  369. StoreOrder::createOrderTemplate($order);
  370. if (StoreOrder::setOrderTypePayOffline($order['order_id']))
  371. return app('json')->status('success', '订单创建成功');
  372. else
  373. return app('json')->status('success', '支付失败');
  374. break;
  375. case "ali":
  376. $orderInfo = StoreOrder::where('order_id', $order['order_id'])->find();
  377. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  378. $orderInfo = $orderInfo->toArray();
  379. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  380. //支付金额为0
  381. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  382. //创建订单jspay支付
  383. $payPriceStatus = StoreOrder::jsPayPrice($order['order_id'], $request->uid());
  384. if ($payPriceStatus)//0元支付成功
  385. return app('json')->status('success', '支付成功');
  386. else
  387. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  388. } else {
  389. try {
  390. $jsConfig = OrderRepository::aliPay($order['order_id']); //创建订单jspay
  391. } catch (\Exception $e) {
  392. return app('json')->status('pay_error', $e->getMessage());
  393. }
  394. $info['jsConfig'] = $jsConfig;
  395. return app('json')->status('ali_pay', '订单创建成功', $info);
  396. }
  397. break;
  398. }
  399. return app('json')->fail('支付方式错误');
  400. }
  401. /**
  402. * 订单列表
  403. * @param Request $request
  404. * @return mixed
  405. */
  406. public function lst(Request $request)
  407. {
  408. list($type, $page, $limit, $search) = UtilService::getMore([
  409. ['type', ''],
  410. ['page', 0],
  411. ['limit', ''],
  412. ['search', ''],
  413. ], $request, true);
  414. return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
  415. }
  416. /**
  417. * 订单详情
  418. * @param Request $request
  419. * @param $uni
  420. * @return mixed
  421. */
  422. public function detail(Request $request, $uni)
  423. {
  424. if (!strlen(trim($uni))) return app('json')->fail('参数错误');
  425. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  426. if (!$order) return app('json')->fail('订单不存在');
  427. $order = $order->toArray();
  428. //是否开启门店自提
  429. $store_self_mention = sys_config('store_self_mention');
  430. //关闭门店自提后 订单隐藏门店信息
  431. if ($store_self_mention == 0) $order['shipping_type'] = 1;
  432. if ($order['verify_code']) {
  433. $verify_code = $order['verify_code'];
  434. $verify[] = substr($verify_code, 0, 4);
  435. $verify[] = substr($verify_code, 4, 4);
  436. $verify[] = substr($verify_code, 8);
  437. $order['_verify_code'] = implode(' ', $verify);
  438. }
  439. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  440. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  441. $order['system_store'] = SystemStore::getStoreDispose($order['store_id']);
  442. if ($order['shipping_type'] === 2 && $order['verify_code']) {
  443. $name = $order['verify_code'] . '.jpg';
  444. $imageInfo = SystemAttachment::getInfo($name, 'name');
  445. $siteUrl = sys_config('site_url');
  446. if (!$imageInfo) {
  447. $imageInfo = UtilService::getQRCodePath($order['verify_code'], $name);
  448. if (is_array($imageInfo)) {
  449. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  450. $url = $imageInfo['dir'];
  451. } else
  452. $url = '';
  453. } else $url = $imageInfo['att_dir'];
  454. if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  455. $order['code'] = $url;
  456. }
  457. $order['mapKey'] = sys_config('tengxun_map_key');
  458. return app('json')->successful('ok', StoreOrder::tidyOrder($order, true, true));
  459. }
  460. /**
  461. * 订单删除
  462. * @param Request $request
  463. * @return mixed
  464. */
  465. public function del(Request $request)
  466. {
  467. list($uni) = UtilService::postMore([
  468. ['uni', ''],
  469. ], $request, true);
  470. if (!$uni) return app('json')->fail('参数错误!');
  471. $res = StoreOrder::removeOrder($uni, $request->uid());
  472. if ($res)
  473. return app('json')->successful();
  474. else
  475. return app('json')->fail(StoreOrder::getErrorInfo());
  476. }
  477. /**
  478. * 订单收货
  479. * @param Request $request
  480. * @return mixed
  481. */
  482. public function take(Request $request)
  483. {
  484. list($uni) = UtilService::postMore([
  485. ['uni', ''],
  486. ], $request, true);
  487. if (!$uni) return app('json')->fail('参数错误!');
  488. $res = StoreOrder::takeOrder($uni, $request->uid());
  489. if ($res) {
  490. $order_info = StoreOrder::where('order_id', $uni)->find();
  491. $gain_integral = intval($order_info['gain_integral']);
  492. $gain_coupon = StoreCouponIssue::alias('a')
  493. ->join('store_coupon b', 'a.cid = b.id')
  494. ->where('a.status', 1)
  495. ->where('a.is_full_give', 1)
  496. ->where('a.is_del', 0)
  497. ->where('a.full_reduction', '<=', $order_info['total_price'])
  498. ->sum('b.coupon_price');
  499. return app('json')->successful(['gain_integral' => $gain_integral, 'gain_coupon' => $gain_coupon]);
  500. } else
  501. return app('json')->fail(StoreOrder::getErrorInfo());
  502. }
  503. /**
  504. * 订单 查看物流
  505. * @param Request $request
  506. * @param $uni
  507. * @return mixed
  508. */
  509. public function express(Request $request, $uni)
  510. {
  511. if (!$uni || !($order = StoreOrder::getUserOrderDetail($request->uid(), $uni))) return app('json')->fail('查询订单不存在!');
  512. if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return app('json')->fail('该订单不存在快递单号!');
  513. $cacheName = $uni . $order['delivery_id'];
  514. $result = CacheService::get($cacheName, null);
  515. if ($result === NULL) {
  516. $result = ExpressService::query($order['delivery_id']);
  517. if (is_array($result) &&
  518. isset($result['result']) &&
  519. isset($result['result']['deliverystatus']) &&
  520. $result['result']['deliverystatus'] >= 3)
  521. $cacheTime = 0;
  522. else
  523. $cacheTime = 1800;
  524. CacheService::set($cacheName, $result, $cacheTime);
  525. }
  526. $orderInfo = [];
  527. $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('cart_info', 'unique') ?? [];
  528. $info = [];
  529. $cartNew = [];
  530. foreach ($cartInfo as $k => $cart) {
  531. $cart = json_decode($cart, true);
  532. $cartNew['cart_num'] = $cart['cart_num'];
  533. $cartNew['truePrice'] = $cart['truePrice'];
  534. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  535. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  536. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  537. array_push($info, $cartNew);
  538. unset($cart);
  539. }
  540. $orderInfo['delivery_id'] = $order['delivery_id'];
  541. $orderInfo['delivery_name'] = $order['delivery_name'];
  542. $orderInfo['delivery_type'] = $order['delivery_type'];
  543. $orderInfo['cartInfo'] = $info;
  544. return app('json')->successful(['order' => $orderInfo, 'express' => $result ? $result : []]);
  545. }
  546. /**
  547. * 订单评价
  548. * @param Request $request
  549. * @return mixed
  550. * @throws \think\db\exception\DataNotFoundException
  551. * @throws \think\db\exception\ModelNotFoundException
  552. * @throws \think\exception\DbException
  553. */
  554. public function comment(Request $request)
  555. {
  556. $group = UtilService::postMore([
  557. ['unique', ''], ['comment', ''], ['pics', ''], ['product_score', 5], ['service_score', 5]
  558. ], $request);
  559. $unique = $group['unique'];
  560. unset($group['unique']);
  561. if (!$unique) return app('json')->fail('参数错误!');
  562. $cartInfo = StoreOrderCartInfo::where('unique', $unique)->find();
  563. $uid = $request->uid();
  564. $user_info = User::get($uid);
  565. $group['nickname'] = $user_info['nickname'];
  566. $group['avatar'] = $user_info['avatar'];
  567. if (!$cartInfo) return app('json')->fail('评价产品不存在!');
  568. $orderUid = StoreOrder::getOrderInfo($cartInfo['oid'], 'uid')['uid'];
  569. if ($uid != $orderUid) return app('json')->fail('评价产品不存在!');
  570. if (StoreProductReply::be(['oid' => $cartInfo['oid'], 'unique' => $unique]))
  571. return app('json')->fail('该产品已评价!');
  572. $group['comment'] = htmlspecialchars(trim($group['comment']));
  573. if ($group['product_score'] < 1) return app('json')->fail('请为产品评分');
  574. else if ($group['service_score'] < 1) return app('json')->fail('请为商家服务评分');
  575. if ($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
  576. else if ($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
  577. else if ($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
  578. else $productId = $cartInfo['product_id'];
  579. if ($group['pics']) $group['pics'] = json_encode(is_array($group['pics']) ? $group['pics'] : explode(',', $group['pics']));
  580. $group = array_merge($group, [
  581. 'uid' => $uid,
  582. 'oid' => $cartInfo['oid'],
  583. 'unique' => $unique,
  584. 'product_id' => $productId,
  585. 'add_time' => time(),
  586. 'reply_type' => 'product'
  587. ]);
  588. StoreProductReply::beginTrans();
  589. $res = StoreProductReply::reply($group, 'product');
  590. if (!$res) {
  591. StoreProductReply::rollbackTrans();
  592. return app('json')->fail('评价失败!');
  593. }
  594. try {
  595. StoreOrder::checkOrderOver($cartInfo['oid']);
  596. } catch (\Exception $e) {
  597. StoreProductReply::rollbackTrans();
  598. return app('json')->fail($e->getMessage());
  599. }
  600. StoreProductReply::commitTrans();
  601. event('UserCommented', $res);
  602. event('AdminNewPush');
  603. return app('json')->successful();
  604. }
  605. /**
  606. * 订单统计数据
  607. * @param Request $request
  608. * @return mixed
  609. */
  610. public function data(Request $request)
  611. {
  612. return app('json')->successful(StoreOrder::getOrderData($request->uid()));
  613. }
  614. /**
  615. * 订单退款理由
  616. * @return mixed
  617. */
  618. public function refund_reason()
  619. {
  620. $reason = sys_config('stor_reason') ?: [];//退款理由
  621. $reason = str_replace("\r\n", "\n", $reason);//防止不兼容
  622. $reason = explode("\n", $reason);
  623. return app('json')->successful($reason);
  624. }
  625. /**
  626. * 订单退款审核
  627. * @param Request $request
  628. * @return mixed
  629. */
  630. public function refund_verify(Request $request)
  631. {
  632. $data = UtilService::postMore([
  633. ['text', ''],
  634. ['refund_reason_wap_img', ''],
  635. ['refund_reason_wap_explain', ''],
  636. ['uni', '']
  637. ], $request);
  638. $uni = $data['uni'];
  639. unset($data['uni']);
  640. if ($data['refund_reason_wap_img']) $data['refund_reason_wap_img'] = explode(',', $data['refund_reason_wap_img']);
  641. if (!$uni || $data['text'] == '') return app('json')->fail('参数错误!');
  642. $res = StoreOrder::orderApplyRefund($uni, $request->uid(), $data['text'], $data['refund_reason_wap_explain'], $data['refund_reason_wap_img']);
  643. if ($res)
  644. return app('json')->successful('提交申请成功');
  645. else
  646. return app('json')->fail(StoreOrder::getErrorInfo());
  647. }
  648. /**
  649. * 订单取消 未支付的订单回退积分,回退优惠券,回退库存
  650. * @param Request $request
  651. * @return mixed
  652. * @throws \think\db\exception\DataNotFoundException
  653. * @throws \think\db\exception\ModelNotFoundException
  654. * @throws \think\exception\DbException
  655. */
  656. public function cancel(Request $request)
  657. {
  658. list($id) = UtilService::postMore([['id', 0]], $request, true);
  659. if (!$id) return app('json')->fail('参数错误');
  660. if (StoreOrder::cancelOrder($id, $request->uid()))
  661. return app('json')->successful('取消订单成功');
  662. return app('json')->fail(StoreOrder::getErrorInfo('取消订单失败'));
  663. }
  664. /**
  665. * 订单产品信息
  666. * @param Request $request
  667. * @return mixed
  668. * @throws \think\db\exception\DataNotFoundException
  669. * @throws \think\db\exception\ModelNotFoundException
  670. * @throws \think\exception\DbException
  671. */
  672. public function product(Request $request)
  673. {
  674. list($unique) = UtilService::postMore([['unique', '']], $request, true);
  675. if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return app('json')->fail('评价产品不存在!');
  676. $cartInfo = $cartInfo->toArray();
  677. $cartProduct = [];
  678. $cartProduct['cart_num'] = $cartInfo['cart_info']['cart_num'];
  679. $cartProduct['productInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['image']) ? $cartInfo['cart_info']['productInfo']['image'] : '';
  680. $cartProduct['productInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['price']) ? $cartInfo['cart_info']['productInfo']['price'] : 0;
  681. $cartProduct['productInfo']['store_name'] = isset($cartInfo['cart_info']['productInfo']['store_name']) ? $cartInfo['cart_info']['productInfo']['store_name'] : '';
  682. if (isset($cartInfo['cart_info']['productInfo']['attrInfo'])) {
  683. $cartProduct['productInfo']['attrInfo']['product_id'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['product_id']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['product_id'] : '';
  684. $cartProduct['productInfo']['attrInfo']['suk'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['suk']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['suk'] : '';
  685. $cartProduct['productInfo']['attrInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['price']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['price'] : '';
  686. $cartProduct['productInfo']['attrInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['image']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['image'] : '';
  687. }
  688. $cartProduct['product_id'] = isset($cartInfo['cart_info']['product_id']) ? $cartInfo['cart_info']['product_id'] : 0;
  689. $cartProduct['combination_id'] = isset($cartInfo['cart_info']['combination_id']) ? $cartInfo['cart_info']['combination_id'] : 0;
  690. $cartProduct['seckill_id'] = isset($cartInfo['cart_info']['seckill_id']) ? $cartInfo['cart_info']['seckill_id'] : 0;
  691. $cartProduct['bargain_id'] = isset($cartInfo['cart_info']['bargain_id']) ? $cartInfo['cart_info']['bargain_id'] : 0;
  692. $cartProduct['order_id'] = StoreOrder::where('id', $cartInfo['oid'])->value('order_id');
  693. return app('json')->successful($cartProduct);
  694. }
  695. /**
  696. * 首页获取未支付订单
  697. */
  698. public function get_noPay(Request $request)
  699. {
  700. return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), 0, 0, 0, ''));
  701. }
  702. =======
  703. <?php
  704. namespace app\api\controller\order;
  705. use app\api\controller\Gmdemo;
  706. use app\admin\model\system\{
  707. SystemAttachment, ShippingTemplates
  708. };
  709. use app\admin\model\user\User;
  710. use app\models\routine\RoutineFormId;
  711. use crmeb\repositories\OrderRepository;
  712. use app\models\store\{
  713. StoreBargainUser,
  714. StoreCart,
  715. StoreCoupon,
  716. StoreCouponIssue,
  717. StoreCouponUser,
  718. StoreOrder,
  719. StoreOrderCartInfo,
  720. StoreOrderStatus,
  721. StorePink,
  722. StoreProductReply
  723. };
  724. use app\models\system\SystemStore;
  725. use app\models\user\UserAddress;
  726. use app\models\user\UserLevel;
  727. use app\Request;
  728. use crmeb\services\{
  729. CacheService,
  730. ExpressService,
  731. SystemConfigService,
  732. UtilService
  733. };
  734. /**
  735. * 订单类
  736. * Class StoreOrderController
  737. * @package app\api\controller\order
  738. */
  739. class StoreOrderController
  740. {
  741. /**
  742. * 订单确认
  743. * @param Request $request
  744. * @return mixed
  745. */
  746. public function confirm(Request $request)
  747. {
  748. $temp = ShippingTemplates::get(1);
  749. if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
  750. list($cartId) = UtilService::postMore(['cartId'], $request, true);
  751. if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品');
  752. $uid = $request->uid();
  753. $cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
  754. if (count($cartGroup['invalid'])) return app('json')->fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
  755. if (!$cartGroup['valid']) return app('json')->fail('请提交购买的商品');
  756. $cartInfo = $cartGroup['valid'];
  757. $addr = UserAddress::where('uid', $uid)->where('is_default', 1)->find();
  758. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
  759. if ($priceGroup === false) {
  760. return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
  761. }
  762. $other = [
  763. 'offlinePostage' => sys_config('offline_postage'),
  764. 'integralRatio' => sys_config('integral_ratio')
  765. ];
  766. $usableCoupons = StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
  767. $usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
  768. $cartIdA = explode(',', $cartId);
  769. $seckill_id = 0;
  770. $combination_id = 0;
  771. $bargain_id = 0;
  772. if (count($cartIdA) == 1) {
  773. $seckill_id = StoreCart::where('id', $cartId)->value('seckill_id');
  774. $combination_id = StoreCart::where('id', $cartId)->value('combination_id');
  775. $bargain_id = StoreCart::where('id', $cartId)->value('bargain_id');
  776. }
  777. $data['deduction'] = $seckill_id || $combination_id || $bargain_id;
  778. $data['usableCoupon'] = $usableCoupon;
  779. $data['addressInfo'] = UserAddress::getUserDefaultAddress($uid);
  780. $data['seckill_id'] = $seckill_id;
  781. $data['combination_id'] = $combination_id;
  782. $data['bargain_id'] = $bargain_id;
  783. $data['cartInfo'] = $cartInfo;
  784. $data['priceGroup'] = $priceGroup;
  785. $data['orderKey'] = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
  786. $data['offlinePostage'] = $other['offlinePostage'];
  787. $vipId = UserLevel::getUserLevel($uid);
  788. $user = $request->user();
  789. if (isset($user['pwd'])) unset($user['pwd']);
  790. $user['vip'] = $vipId !== false ? true : false;
  791. if ($user['vip']) {
  792. $user['vip_id'] = $vipId;
  793. $user['discount'] = UserLevel::getUserLevelInfo($vipId, 'discount');
  794. }
  795. $data['userInfo'] = $user;
  796. $data['integralRatio'] = $other['integralRatio'];
  797. $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2;
  798. $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
  799. $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];//门店信息
  800. return app('json')->successful($data);
  801. }
  802. /**
  803. * 计算订单金额
  804. * @param Request $request
  805. * @param $key
  806. * @return mixed
  807. * @throws \think\Exception
  808. * @throws \think\db\exception\DataNotFoundException
  809. * @throws \think\db\exception\ModelNotFoundException
  810. * @throws \think\exception\DbException
  811. */
  812. public function computedOrder(Request $request, $key)
  813. {
  814. // $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
  815. if (!$key) return app('json')->fail('参数错误!');
  816. $uid = $request->uid();
  817. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  818. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  819. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
  820. 'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
  821. ['shipping_type', 1],
  822. ], $request, true);
  823. $payType = strtolower($payType);
  824. if ($bargainId) {
  825. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  826. if (!$bargainUserTableId)
  827. return app('json')->fail('砍价失败');
  828. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  829. if ($status == 3)
  830. return app('json')->fail('砍价已支付');
  831. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  832. }
  833. if ($pinkId) {
  834. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  835. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  836. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  837. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  838. }
  839. $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
  840. if ($priceGroup)
  841. return app('json')->status('NONE', 'ok', $priceGroup);
  842. else
  843. return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
  844. }
  845. /**
  846. * 订单创建
  847. * @param Request $request
  848. * @param $key
  849. * @return mixed
  850. * @throws \think\Exception
  851. * @throws \think\db\exception\DataNotFoundException
  852. * @throws \think\db\exception\ModelNotFoundException
  853. * @throws \think\exception\DbException
  854. */
  855. public function create(Request $request, $key)
  856. {
  857. if (!$key) return app('json')->fail('参数错误!');
  858. $uid = $request->uid();
  859. if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
  860. return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
  861. list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
  862. 'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
  863. ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
  864. ], $request, true);
  865. $payType = strtolower($payType);
  866. if ($bargainId) {
  867. $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
  868. if (!$bargainUserTableId)
  869. return app('json')->fail('砍价失败');
  870. $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
  871. if ($status == 3)
  872. return app('json')->fail('砍价已支付');
  873. StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
  874. }
  875. if ($pinkId) {
  876. if (StorePink::getIsPinkUid($pinkId, $request->uid()))
  877. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  878. if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
  879. return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
  880. }
  881. $isChannel = 1;
  882. if ($from == 'weixin')
  883. $isChannel = 0;
  884. elseif ($from == 'weixinh5')
  885. $isChannel = 2;
  886. $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId);
  887. if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
  888. $orderId = $order['order_id'];
  889. $info = compact('orderId', 'key');
  890. if ($orderId) {
  891. event('OrderCreated', [$order]); //订单创建成功事件
  892. event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
  893. switch ($payType) {
  894. case "weixin":
  895. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  896. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  897. $orderInfo = $orderInfo->toArray();
  898. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  899. //支付金额为0
  900. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  901. //创建订单jspay支付
  902. $payPriceStatus = StoreOrder::jsPayPrice($orderId, $uid, $formId);
  903. if ($payPriceStatus)//0元支付成功
  904. return app('json')->status('success', '微信支付成功', $info);
  905. else
  906. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  907. } else {
  908. try {
  909. if ($from == 'routine') {
  910. $jsConfig = OrderRepository::jsPay($orderId); //创建订单jspay
  911. } else if ($from == 'weixinh5') {
  912. $jsConfig = OrderRepository::h5Pay($orderId);
  913. } else {
  914. $jsConfig = OrderRepository::wxPay($orderId);
  915. }
  916. } catch (\Exception $e) {
  917. return app('json')->status('pay_error', $e->getMessage(), $info);
  918. }
  919. $info['jsConfig'] = $jsConfig;
  920. if ($from == 'weixinh5') {
  921. return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
  922. } else {
  923. return app('json')->status('wechat_pay', '订单创建成功', $info);
  924. }
  925. }
  926. break;
  927. case "ali":
  928. $orderInfo = StoreOrder::where('order_id', $orderId)->find();
  929. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  930. $orderInfo = $orderInfo->toArray();
  931. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  932. //支付金额为0
  933. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  934. //创建订单jspay支付
  935. $payPriceStatus = StoreOrder::jsPayPrice($orderId, $request->uid());
  936. if ($payPriceStatus)//0元支付成功
  937. return app('json')->status('success', '支付成功');
  938. else
  939. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  940. } else {
  941. try {
  942. $jsConfig = OrderRepository::aliPay($orderId); //创建订单jspay
  943. } catch (\Exception $e) {
  944. return app('json')->status('pay_error', $e->getMessage());
  945. }
  946. $info['jsConfig'] = $jsConfig;
  947. return app('json')->status('ali_pay', '订单创建成功', $info);
  948. }
  949. break;
  950. case 'yue':
  951. if (StoreOrder::yuePay($orderId, $request->uid(), $formId))
  952. return app('json')->status('success', '余额支付成功', $info);
  953. else {
  954. $errorinfo = StoreOrder::getErrorInfo();
  955. if (is_array($errorinfo))
  956. return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
  957. else
  958. return app('json')->status('pay_error', $errorinfo);
  959. }
  960. break;
  961. case 'offline':
  962. return app('json')->status('success', '订单创建成功', $info);
  963. break;
  964. }
  965. } else return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
  966. }
  967. /**
  968. * 订单 再次下单
  969. * @param Request $request
  970. * @return mixed
  971. */
  972. public function again(Request $request)
  973. {
  974. list($uni) = UtilService::postMore([
  975. ['uni', ''],
  976. ], $request, true);
  977. if (!$uni) return app('json')->fail('参数错误!');
  978. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  979. if (!$order) return app('json')->fail('订单不存在!');
  980. $order = StoreOrder::tidyOrder($order, true);
  981. $res = [];
  982. foreach ($order['cartInfo'] as $v) {
  983. if ($v['combination_id']) return app('json')->fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
  984. else if ($v['bargain_id']) return app('json')->fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
  985. else if ($v['seckill_id']) return app('json')->ail('秒杀产品不能再来一单,请在秒杀产品内自行下单!');
  986. else $res[] = StoreCart::setCart($request->uid(), $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
  987. }
  988. $cateId = [];
  989. foreach ($res as $v) {
  990. if (!$v) return app('json')->fail('再来一单失败,请重新下单!');
  991. $cateId[] = $v['id'];
  992. }
  993. event('OrderCreateAgain', implode(',', $cateId));
  994. return app('json')->successful('ok', ['cateId' => implode(',', $cateId)]);
  995. }
  996. /**
  997. * 订单支付
  998. * @param Request $request
  999. * @return mixed
  1000. */
  1001. public function pay(Request $request)
  1002. {
  1003. list($uni, $paytype, $from) = UtilService::postMore([
  1004. ['uni', ''],
  1005. ['paytype', 'weixin'],
  1006. ['from', 'weixin']
  1007. ], $request, true);
  1008. if (!$uni) return app('json')->fail('参数错误!');
  1009. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  1010. if (!$order)
  1011. return app('json')->fail('订单不存在!');
  1012. if ($order['paid'])
  1013. return app('json')->fail('该订单已支付!');
  1014. if ($order['pink_id']) if (StorePink::isPinkStatus($order['pink_id']))
  1015. return app('json')->fail('该订单已失效!');
  1016. if ($from == 'weixin') {//0
  1017. if (in_array($order->is_channel, [1, 2]))
  1018. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  1019. }
  1020. if ($from == 'weixinh5') {//2
  1021. if (in_array($order->is_channel, [0, 1]))
  1022. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  1023. }
  1024. if ($from == 'routine') {//1
  1025. if (in_array($order->is_channel, [0, 2]))
  1026. $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
  1027. }
  1028. $order['pay_type'] = $paytype; //重新支付选择支付方式
  1029. switch ($order['pay_type']) {
  1030. case 'weixin':
  1031. try {
  1032. if ($from == 'routine') {
  1033. $jsConfig = OrderRepository::jsPay($order); //订单列表发起支付
  1034. } else if ($from == 'weixinh5') {
  1035. $jsConfig = OrderRepository::h5Pay($order);
  1036. } else {
  1037. $jsConfig = OrderRepository::wxPay($order);
  1038. }
  1039. } catch (\Exception $e) {
  1040. return app('json')->fail($e->getMessage());
  1041. }
  1042. if ($from == 'weixinh5') {
  1043. return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  1044. } else {
  1045. return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
  1046. }
  1047. break;
  1048. case 'yue':
  1049. if (StoreOrder::yuePay($order['order_id'], $request->uid()))
  1050. return app('json')->status('success', '余额支付成功');
  1051. else {
  1052. $error = StoreOrder::getErrorInfo();
  1053. return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
  1054. }
  1055. break;
  1056. case 'ztpay':
  1057. $gm = new Gmdemo();
  1058. $data = [
  1059. 'mechNo' => 123456,// 商户号
  1060. 'inetNo' => $order['order_id'],//订单号
  1061. 'sndTmstmp' => date('YmdHis', time()),
  1062. 'pdDsc' => '=商品购买',
  1063. 'pymntAmt' => $order['pay_price'] * 100, // 交 易 单 位 为 分
  1064. 'ccy' => 156,
  1065. 'channelCode' => ''//渠道号
  1066. ];
  1067. $res = $gm->scanPaymentCode($data);
  1068. halt($res);
  1069. case 'offline':
  1070. StoreOrder::createOrderTemplate($order);
  1071. if (StoreOrder::setOrderTypePayOffline($order['order_id']))
  1072. return app('json')->status('success', '订单创建成功');
  1073. else
  1074. return app('json')->status('success', '支付失败');
  1075. break;
  1076. case "ali":
  1077. $orderInfo = StoreOrder::where('order_id', $order['order_id'])->find();
  1078. if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
  1079. $orderInfo = $orderInfo->toArray();
  1080. if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
  1081. //支付金额为0
  1082. if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
  1083. //创建订单jspay支付
  1084. $payPriceStatus = StoreOrder::jsPayPrice($order['order_id'], $request->uid());
  1085. if ($payPriceStatus)//0元支付成功
  1086. return app('json')->status('success', '支付成功');
  1087. else
  1088. return app('json')->status('pay_error', StoreOrder::getErrorInfo());
  1089. } else {
  1090. try {
  1091. $jsConfig = OrderRepository::aliPay($order['order_id']); //创建订单jspay
  1092. } catch (\Exception $e) {
  1093. return app('json')->status('pay_error', $e->getMessage());
  1094. }
  1095. $info['jsConfig'] = $jsConfig;
  1096. return app('json')->status('ali_pay', '订单创建成功', $info);
  1097. }
  1098. break;
  1099. }
  1100. return app('json')->fail('支付方式错误');
  1101. }
  1102. /**
  1103. * 订单列表
  1104. * @param Request $request
  1105. * @return mixed
  1106. */
  1107. public function lst(Request $request)
  1108. {
  1109. list($type, $page, $limit, $search) = UtilService::getMore([
  1110. ['type', ''],
  1111. ['page', 0],
  1112. ['limit', ''],
  1113. ['search', ''],
  1114. ], $request, true);
  1115. return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
  1116. }
  1117. /**
  1118. * 订单详情
  1119. * @param Request $request
  1120. * @param $uni
  1121. * @return mixed
  1122. */
  1123. public function detail(Request $request, $uni)
  1124. {
  1125. if (!strlen(trim($uni))) return app('json')->fail('参数错误');
  1126. $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
  1127. if (!$order) return app('json')->fail('订单不存在');
  1128. $order = $order->toArray();
  1129. //是否开启门店自提
  1130. $store_self_mention = sys_config('store_self_mention');
  1131. //关闭门店自提后 订单隐藏门店信息
  1132. if ($store_self_mention == 0) $order['shipping_type'] = 1;
  1133. if ($order['verify_code']) {
  1134. $verify_code = $order['verify_code'];
  1135. $verify[] = substr($verify_code, 0, 4);
  1136. $verify[] = substr($verify_code, 4, 4);
  1137. $verify[] = substr($verify_code, 8);
  1138. $order['_verify_code'] = implode(' ', $verify);
  1139. }
  1140. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  1141. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  1142. $order['system_store'] = SystemStore::getStoreDispose($order['store_id']);
  1143. if ($order['shipping_type'] === 2 && $order['verify_code']) {
  1144. $name = $order['verify_code'] . '.jpg';
  1145. $imageInfo = SystemAttachment::getInfo($name, 'name');
  1146. $siteUrl = sys_config('site_url');
  1147. if (!$imageInfo) {
  1148. $imageInfo = UtilService::getQRCodePath($order['verify_code'], $name);
  1149. if (is_array($imageInfo)) {
  1150. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  1151. $url = $imageInfo['dir'];
  1152. } else
  1153. $url = '';
  1154. } else $url = $imageInfo['att_dir'];
  1155. if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  1156. $order['code'] = $url;
  1157. }
  1158. $order['mapKey'] = sys_config('tengxun_map_key');
  1159. return app('json')->successful('ok', StoreOrder::tidyOrder($order, true, true));
  1160. }
  1161. /**
  1162. * 订单删除
  1163. * @param Request $request
  1164. * @return mixed
  1165. */
  1166. public function del(Request $request)
  1167. {
  1168. list($uni) = UtilService::postMore([
  1169. ['uni', ''],
  1170. ], $request, true);
  1171. if (!$uni) return app('json')->fail('参数错误!');
  1172. $res = StoreOrder::removeOrder($uni, $request->uid());
  1173. if ($res)
  1174. return app('json')->successful();
  1175. else
  1176. return app('json')->fail(StoreOrder::getErrorInfo());
  1177. }
  1178. /**
  1179. * 订单收货
  1180. * @param Request $request
  1181. * @return mixed
  1182. */
  1183. public function take(Request $request)
  1184. {
  1185. list($uni) = UtilService::postMore([
  1186. ['uni', ''],
  1187. ], $request, true);
  1188. if (!$uni) return app('json')->fail('参数错误!');
  1189. $res = StoreOrder::takeOrder($uni, $request->uid());
  1190. if ($res) {
  1191. $order_info = StoreOrder::where('order_id', $uni)->find();
  1192. $gain_integral = intval($order_info['gain_integral']);
  1193. $gain_coupon = StoreCouponIssue::alias('a')
  1194. ->join('store_coupon b', 'a.cid = b.id')
  1195. ->where('a.status', 1)
  1196. ->where('a.is_full_give', 1)
  1197. ->where('a.is_del', 0)
  1198. ->where('a.full_reduction', '<=', $order_info['total_price'])
  1199. ->sum('b.coupon_price');
  1200. return app('json')->successful(['gain_integral' => $gain_integral, 'gain_coupon' => $gain_coupon]);
  1201. } else
  1202. return app('json')->fail(StoreOrder::getErrorInfo());
  1203. }
  1204. /**
  1205. * 订单 查看物流
  1206. * @param Request $request
  1207. * @param $uni
  1208. * @return mixed
  1209. */
  1210. public function express(Request $request, $uni)
  1211. {
  1212. if (!$uni || !($order = StoreOrder::getUserOrderDetail($request->uid(), $uni))) return app('json')->fail('查询订单不存在!');
  1213. if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return app('json')->fail('该订单不存在快递单号!');
  1214. $cacheName = $uni . $order['delivery_id'];
  1215. $result = CacheService::get($cacheName, null);
  1216. if ($result === NULL) {
  1217. $result = ExpressService::query($order['delivery_id']);
  1218. if (is_array($result) &&
  1219. isset($result['result']) &&
  1220. isset($result['result']['deliverystatus']) &&
  1221. $result['result']['deliverystatus'] >= 3)
  1222. $cacheTime = 0;
  1223. else
  1224. $cacheTime = 1800;
  1225. CacheService::set($cacheName, $result, $cacheTime);
  1226. }
  1227. $orderInfo = [];
  1228. $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('cart_info', 'unique') ?? [];
  1229. $info = [];
  1230. $cartNew = [];
  1231. foreach ($cartInfo as $k => $cart) {
  1232. $cart = json_decode($cart, true);
  1233. $cartNew['cart_num'] = $cart['cart_num'];
  1234. $cartNew['truePrice'] = $cart['truePrice'];
  1235. $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
  1236. $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
  1237. $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
  1238. array_push($info, $cartNew);
  1239. unset($cart);
  1240. }
  1241. $orderInfo['delivery_id'] = $order['delivery_id'];
  1242. $orderInfo['delivery_name'] = $order['delivery_name'];
  1243. $orderInfo['delivery_type'] = $order['delivery_type'];
  1244. $orderInfo['cartInfo'] = $info;
  1245. return app('json')->successful(['order' => $orderInfo, 'express' => $result ? $result : []]);
  1246. }
  1247. /**
  1248. * 订单评价
  1249. * @param Request $request
  1250. * @return mixed
  1251. * @throws \think\db\exception\DataNotFoundException
  1252. * @throws \think\db\exception\ModelNotFoundException
  1253. * @throws \think\exception\DbException
  1254. */
  1255. public function comment(Request $request)
  1256. {
  1257. $group = UtilService::postMore([
  1258. ['unique', ''], ['comment', ''], ['pics', ''], ['product_score', 5], ['service_score', 5]
  1259. ], $request);
  1260. $unique = $group['unique'];
  1261. unset($group['unique']);
  1262. if (!$unique) return app('json')->fail('参数错误!');
  1263. $cartInfo = StoreOrderCartInfo::where('unique', $unique)->find();
  1264. $uid = $request->uid();
  1265. $user_info = User::get($uid);
  1266. $group['nickname'] = $user_info['nickname'];
  1267. $group['avatar'] = $user_info['avatar'];
  1268. if (!$cartInfo) return app('json')->fail('评价产品不存在!');
  1269. $orderUid = StoreOrder::getOrderInfo($cartInfo['oid'], 'uid')['uid'];
  1270. if ($uid != $orderUid) return app('json')->fail('评价产品不存在!');
  1271. if (StoreProductReply::be(['oid' => $cartInfo['oid'], 'unique' => $unique]))
  1272. return app('json')->fail('该产品已评价!');
  1273. $group['comment'] = htmlspecialchars(trim($group['comment']));
  1274. if ($group['product_score'] < 1) return app('json')->fail('请为产品评分');
  1275. else if ($group['service_score'] < 1) return app('json')->fail('请为商家服务评分');
  1276. if ($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
  1277. else if ($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
  1278. else if ($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
  1279. else $productId = $cartInfo['product_id'];
  1280. if ($group['pics']) $group['pics'] = json_encode(is_array($group['pics']) ? $group['pics'] : explode(',', $group['pics']));
  1281. $group = array_merge($group, [
  1282. 'uid' => $uid,
  1283. 'oid' => $cartInfo['oid'],
  1284. 'unique' => $unique,
  1285. 'product_id' => $productId,
  1286. 'add_time' => time(),
  1287. 'reply_type' => 'product'
  1288. ]);
  1289. StoreProductReply::beginTrans();
  1290. $res = StoreProductReply::reply($group, 'product');
  1291. if (!$res) {
  1292. StoreProductReply::rollbackTrans();
  1293. return app('json')->fail('评价失败!');
  1294. }
  1295. try {
  1296. StoreOrder::checkOrderOver($cartInfo['oid']);
  1297. } catch (\Exception $e) {
  1298. StoreProductReply::rollbackTrans();
  1299. return app('json')->fail($e->getMessage());
  1300. }
  1301. StoreProductReply::commitTrans();
  1302. event('UserCommented', $res);
  1303. event('AdminNewPush');
  1304. return app('json')->successful();
  1305. }
  1306. /**
  1307. * 订单统计数据
  1308. * @param Request $request
  1309. * @return mixed
  1310. */
  1311. public function data(Request $request)
  1312. {
  1313. return app('json')->successful(StoreOrder::getOrderData($request->uid()));
  1314. }
  1315. /**
  1316. * 订单退款理由
  1317. * @return mixed
  1318. */
  1319. public function refund_reason()
  1320. {
  1321. $reason = sys_config('stor_reason') ?: [];//退款理由
  1322. $reason = str_replace("\r\n", "\n", $reason);//防止不兼容
  1323. $reason = explode("\n", $reason);
  1324. return app('json')->successful($reason);
  1325. }
  1326. /**
  1327. * 订单退款审核
  1328. * @param Request $request
  1329. * @return mixed
  1330. */
  1331. public function refund_verify(Request $request)
  1332. {
  1333. $data = UtilService::postMore([
  1334. ['text', ''],
  1335. ['refund_reason_wap_img', ''],
  1336. ['refund_reason_wap_explain', ''],
  1337. ['uni', '']
  1338. ], $request);
  1339. $uni = $data['uni'];
  1340. unset($data['uni']);
  1341. if ($data['refund_reason_wap_img']) $data['refund_reason_wap_img'] = explode(',', $data['refund_reason_wap_img']);
  1342. if (!$uni || $data['text'] == '') return app('json')->fail('参数错误!');
  1343. $res = StoreOrder::orderApplyRefund($uni, $request->uid(), $data['text'], $data['refund_reason_wap_explain'], $data['refund_reason_wap_img']);
  1344. if ($res)
  1345. return app('json')->successful('提交申请成功');
  1346. else
  1347. return app('json')->fail(StoreOrder::getErrorInfo());
  1348. }
  1349. /**
  1350. * 订单取消 未支付的订单回退积分,回退优惠券,回退库存
  1351. * @param Request $request
  1352. * @return mixed
  1353. * @throws \think\db\exception\DataNotFoundException
  1354. * @throws \think\db\exception\ModelNotFoundException
  1355. * @throws \think\exception\DbException
  1356. */
  1357. public function cancel(Request $request)
  1358. {
  1359. list($id) = UtilService::postMore([['id', 0]], $request, true);
  1360. if (!$id) return app('json')->fail('参数错误');
  1361. if (StoreOrder::cancelOrder($id, $request->uid()))
  1362. return app('json')->successful('取消订单成功');
  1363. return app('json')->fail(StoreOrder::getErrorInfo('取消订单失败'));
  1364. }
  1365. /**
  1366. * 订单产品信息
  1367. * @param Request $request
  1368. * @return mixed
  1369. * @throws \think\db\exception\DataNotFoundException
  1370. * @throws \think\db\exception\ModelNotFoundException
  1371. * @throws \think\exception\DbException
  1372. */
  1373. public function product(Request $request)
  1374. {
  1375. list($unique) = UtilService::postMore([['unique', '']], $request, true);
  1376. if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return app('json')->fail('评价产品不存在!');
  1377. $cartInfo = $cartInfo->toArray();
  1378. $cartProduct = [];
  1379. $cartProduct['cart_num'] = $cartInfo['cart_info']['cart_num'];
  1380. $cartProduct['productInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['image']) ? $cartInfo['cart_info']['productInfo']['image'] : '';
  1381. $cartProduct['productInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['price']) ? $cartInfo['cart_info']['productInfo']['price'] : 0;
  1382. $cartProduct['productInfo']['store_name'] = isset($cartInfo['cart_info']['productInfo']['store_name']) ? $cartInfo['cart_info']['productInfo']['store_name'] : '';
  1383. if (isset($cartInfo['cart_info']['productInfo']['attrInfo'])) {
  1384. $cartProduct['productInfo']['attrInfo']['product_id'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['product_id']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['product_id'] : '';
  1385. $cartProduct['productInfo']['attrInfo']['suk'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['suk']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['suk'] : '';
  1386. $cartProduct['productInfo']['attrInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['price']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['price'] : '';
  1387. $cartProduct['productInfo']['attrInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['image']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['image'] : '';
  1388. }
  1389. $cartProduct['product_id'] = isset($cartInfo['cart_info']['product_id']) ? $cartInfo['cart_info']['product_id'] : 0;
  1390. $cartProduct['combination_id'] = isset($cartInfo['cart_info']['combination_id']) ? $cartInfo['cart_info']['combination_id'] : 0;
  1391. $cartProduct['seckill_id'] = isset($cartInfo['cart_info']['seckill_id']) ? $cartInfo['cart_info']['seckill_id'] : 0;
  1392. $cartProduct['bargain_id'] = isset($cartInfo['cart_info']['bargain_id']) ? $cartInfo['cart_info']['bargain_id'] : 0;
  1393. $cartProduct['order_id'] = StoreOrder::where('id', $cartInfo['oid'])->value('order_id');
  1394. return app('json')->successful($cartProduct);
  1395. }
  1396. /**
  1397. * 首页获取未支付订单
  1398. */
  1399. public function get_noPay(Request $request)
  1400. {
  1401. return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), 0, 0, 0, ''));
  1402. }
  1403. >>>>>>> 386b37d33e5ba817cba00df29efaefbd692e4dd1
  1404. }