OrderController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. <?php
  2. namespace mall\controllers;
  3. use biz\product\classes\ProductClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\wx\classes\WxMessageClass;
  6. use bizHd\custom\classes\HdClass;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use bizMall\custom\classes\CustomClass;
  9. use bizMall\goods\classes\GoodsClass;
  10. use bizMall\goods\classes\GoodsSettingClass;
  11. use bizMall\item\classes\ItemClass;
  12. use bizMall\order\classes\OrderClass;
  13. use bizMall\order\classes\OrderForwardClass;
  14. use bizMall\order\classes\OrderItemClass;
  15. use bizMall\order\services\OrderService;
  16. use bizMall\promote\services\CouponService;
  17. use bizMall\saas\services\RegionService;
  18. use bizMall\shop\classes\MainClass;
  19. use bizMall\shop\classes\ShopExtClass;
  20. use bizMall\user\services\UserService;
  21. use common\components\dateUtil;
  22. use common\components\dict;
  23. use common\components\imgUtil;
  24. use common\components\noticeUtil;
  25. use common\components\orderSn;
  26. use common\components\stringUtil;
  27. use common\services\xhPayToolService;
  28. use Yii;
  29. use common\components\util;
  30. use common\components\lakala\Lakala;
  31. use common\components\IntraCityExpress;
  32. class OrderController extends BaseController
  33. {
  34. //二维码收款使用
  35. public $guestAccess = ['order-relate', 'fast-pay'];
  36. //记账单列表 ssh 20250627
  37. public function actionDebtList()
  38. {
  39. $get = Yii::$app->request->get();
  40. $id = $get['id'] ?? 0;
  41. $where = [];
  42. $where['userId'] = $this->userId;
  43. if (!empty($id)) {
  44. $hd = \bizMall\hd\classes\HdClass::getById($id, true);
  45. if (empty($hd)) {
  46. util::fail('无效的花店');
  47. }
  48. $where['hdId'] = $id;
  49. }
  50. $where['debt'] = 1;
  51. $searchTime = $get['searchTime'] ?? '';
  52. if (!empty($searchTime)) {
  53. $startTime = $get['startTime'] ?? '';
  54. $endTime = $get['endTime'] ?? '';
  55. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  56. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  57. }
  58. $respond = OrderClass::getDebtList($where);
  59. util::success($respond);
  60. }
  61. //新计算运费
  62. public function actionNewFreight()
  63. {
  64. $post = Yii::$app->request->post();
  65. $hasMap = dict::getDict('hasMap');
  66. if ($hasMap == 0) {
  67. util::fail('暂不支持跑腿功能');
  68. }
  69. $mainData = $this->main;
  70. $wxStoreId = $mainData->wxStoreId ?? '';
  71. if (empty($wxStoreId)) {
  72. util::fail('商家还没有开通跑腿');
  73. }
  74. $cargoName = $post['cargo_name']; // 商品名称
  75. $cargo = [
  76. 'cargo_name' => $cargoName, // 商品名称
  77. 'cargo_weight' => intval($post['weight'] * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  78. 'cargo_price' => intval($post['price'] * 100), // 单位:分 -- 把元转换为分
  79. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  80. 'cargo_num' => intval($post['package_num'])
  81. ];
  82. $originalLng = doubleval($post['user_lng']);
  83. $originalLat = doubleval($post['user_lat']);
  84. $orderData = [
  85. 'wx_store_id' => $wxStoreId,
  86. 'user_name' => $post['user_name'],
  87. 'user_phone' => $post['user_phone'],
  88. 'user_lng' => $originalLng,
  89. 'user_lat' => $originalLat,
  90. 'user_address' => $post['user_address'],
  91. 'cargo' => $cargo,
  92. ];
  93. //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  94. $result = IntraCityExpress::preAddOrder($orderData);
  95. if ($result['errcode'] === 0) {
  96. util::success($result, "查询成功");
  97. } else {
  98. Yii::error("运费查询失败:" . json_encode($result));
  99. util::fail('运费查询失败' . json_encode($result));
  100. }
  101. }
  102. //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
  103. public function actionFreight()
  104. {
  105. $get = Yii::$app->request->get();
  106. $shop = $this->shop;
  107. $shopLat = isset($shop->lat) ? $shop->lat : '';
  108. $shopLong = isset($shop->long) ? $shop->long : '';
  109. // 判断地图功能是否正常。0 表示地图定位不可用,全部经纬度数据失效
  110. if (dict::getDict('hasMap') == 0) {
  111. $shopLat = '';
  112. $shopLong = '';
  113. }
  114. if (empty($shopLat) || empty($shopLong)) {
  115. util::success([
  116. 'distance' => 0,
  117. 'showDistance' => 0,
  118. 'fee' => 0,
  119. 'hasMap' => dict::getDict('hasMap'),
  120. 'shop' => 'fail' //门店引起的失败
  121. ]);
  122. }
  123. $userLat = $get['lat'] ?? '';
  124. $userLong = $get['long'] ?? '';
  125. if (empty($userLat) || empty($userLong)) {
  126. util::success([
  127. 'distance' => 0,
  128. 'showDistance' => 0,
  129. 'fee' => 0,
  130. 'hasMap' => dict::getDict('hasMap'),
  131. 'client' => 'fail' //用户端定位失败
  132. ]);
  133. }
  134. $weight = $get['weight'] ?? 0;
  135. if (empty($weight)) {
  136. util::success([
  137. 'distance' => 0,
  138. 'showDistance' => 0,
  139. 'fee' => 0,
  140. 'hasMap' => dict::getDict('hasMap'),
  141. 'weight' => 'fail' //重量不对
  142. ]);
  143. }
  144. //data: {distance: "321", showDistance: "0.3", fee: "12.00"}
  145. $respond = OrderClass::getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight);
  146. util::success($respond);
  147. }
  148. //购买花材 ssh 20220511
  149. public function actionBuyItem()
  150. {
  151. $post = Yii::$app->request->post();
  152. $post['sjId'] = $this->sjId;
  153. $post['shopId'] = $this->shopId;
  154. $post['payWay'] = 0;
  155. $post['mainId'] = $this->mainId ?? 0;
  156. $post['userId'] = $this->userId ?? 0;
  157. //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
  158. $mainId = $this->mainId;
  159. if (getenv('YII_ENV') == 'production') {
  160. if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) {
  161. util::fail('暂时无法访问');
  162. }
  163. } else {
  164. if (in_array($mainId, [0, 1])) {
  165. util::fail('暂时无法访问');
  166. }
  167. }
  168. $hdId = $post['hdId'] ?? 0;
  169. $hd = HdClass::getById($hdId, true);
  170. if (empty($hd)) {
  171. util::fail('没有找到花店');
  172. }
  173. if ($hd->shopId != $this->shopId) {
  174. util::fail('不是你的花店');
  175. }
  176. $post['hdName'] = $hd->name ?? '';
  177. $customId = $hd->customId ?? 0;
  178. $custom = CustomClass::getById($customId, true);
  179. if (empty($custom)) {
  180. util::fail('没有找到客户');
  181. }
  182. $customName = $custom->name ?? '';
  183. $post['customId'] = $customId;
  184. $post['customName'] = $customName;
  185. $post['customNamePy'] = stringUtil::py($customName);
  186. $now = time();
  187. //订单30分钟后过期
  188. $expireTime = $now + 1800;
  189. $post['deadline'] = $expireTime;
  190. //商城
  191. $post['fromType'] = dict::getDict('fromType', 'mall');
  192. $productJson = $post['product'] ?? '';
  193. if (empty($productJson) && empty($groupId)) {
  194. util::fail('请选择商品');
  195. }
  196. $productList = json_decode($productJson, true);
  197. if (empty($productList)) {
  198. util::fail('请选择商品');
  199. }
  200. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  201. $productInfoList = productClass::getByIds($ids, null, 'id');
  202. if (!empty($productInfoList)) {
  203. $presellData = [];
  204. $nowTime = strtotime(date("Y-m-d"));
  205. foreach ($productInfoList as $currentInfo) {
  206. if (!isset($currentInfo['mainId']) || $currentInfo['mainId'] != $this->mainId) {
  207. util::fail('只能选择同一家的商品哦');
  208. }
  209. $currentName = $currentInfo['name'] ?? '';
  210. $presell = $currentInfo['presell'] ?? 0;
  211. $presellData[] = $presell;
  212. if ($presell == 1) {
  213. if (empty($post['reachDate'])) {
  214. util::fail('请选择配送或取货日期');
  215. }
  216. $sendTimeWant = $post['reachDate'];
  217. if (strtotime($sendTimeWant) < $nowTime) {
  218. util::fail('不能选择过去时间');
  219. }
  220. $hasDateStr = $currentInfo['presellDate'] ?? [];
  221. $hasDate = explode(',', trim($hasDateStr));
  222. if (empty($hasDate)) {
  223. util::fail('预售日期有问题,请提醒门店');
  224. }
  225. if (!in_array(strtotime($sendTimeWant), $hasDate)) {
  226. util::fail("有预售花材在{$sendTimeWant}没到货");
  227. }
  228. $post['presell'] = 1;
  229. }
  230. }
  231. if (count($productInfoList) != count($ids)) {
  232. util::fail('存在无效商品');
  233. }
  234. $presellData = array_unique($presellData);
  235. if (count($presellData) > 1) {
  236. util::fail('预售和非预售花材不能一起下单');
  237. }
  238. } else {
  239. util::fail('花材不存在');
  240. }
  241. $connection = Yii::$app->db;
  242. $transaction = $connection->beginTransaction();
  243. try {
  244. $orderValidTime = !getenv('ORDER_VALID_TIME') ? 600 : getenv('ORDER_VALID_TIME');
  245. $post['deadline'] = time() + $orderValidTime;
  246. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  247. $post['needPrint'] = dict::getDict('needPrint', 'need');
  248. $user = $this->user;
  249. $post['bookMobile'] = $user->mobile ?? '';
  250. $post['bookName'] = $user->name ?? '';
  251. $hasPay = 0;
  252. $modifyPrice = 0;
  253. //各个等级对应的price addPrice字段
  254. $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
  255. $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
  256. $totalWeight = 0;
  257. $totalNum = 0;
  258. foreach ($productList as $eleKey => $element) {
  259. $level = 0;
  260. $productId = $element['productId'];
  261. $current = $productInfoList[$productId];
  262. if (empty($current)) {
  263. util::fail('有商品信息没有找到');
  264. }
  265. $price = \bizGhs\product\classes\ProductClass::getFinalPrice($current, $level, $priceMap, $addPriceMap);
  266. $num = $element['num'] ?? 0;
  267. $currentTotal = bcmul($price, $num, 2);
  268. $modifyPrice = bcadd($modifyPrice, $currentTotal, 2);
  269. $productList[$eleKey]['unitPrice'] = $price;
  270. $weight = $current['weight'] ?? 0;
  271. $currentWeight = bcmul($num, $weight, 2);
  272. $totalWeight = bcadd($totalWeight, $currentWeight, 2);
  273. $totalNum = bcadd($totalNum, $num);
  274. }
  275. $post['product'] = $productList;
  276. //不能前端传运费过来,只能通过跑腿接口计算出来
  277. unset($post['sendCost']);
  278. if (isset($post['sendType']) && $post['sendType'] == 2) {
  279. $hasMap = dict::getDict('hasMap');
  280. if ($hasMap == 0) {
  281. util::fail('不能使用跑腿,请选其它方式');
  282. }
  283. $cargoName = '花材'; // 商品名称
  284. $cargo = [
  285. 'cargo_name' => $cargoName, // 商品名称
  286. 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  287. 'cargo_price' => intval($modifyPrice * 100), // 单位:分 -- 把元转换为分
  288. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  289. 'cargo_num' => $totalNum
  290. ];
  291. $customName = $custom->name;
  292. $customMobile = $custom->mobile;
  293. if (empty($post['long']) || empty($post['lat'])) {
  294. util::fail('位置错误');
  295. }
  296. $originalLng = doubleval($post['long']);
  297. $originalLat = doubleval($post['lat']);
  298. $city = $post['city'] ?? '';
  299. $dist = $post['dist'] ?? '';
  300. $address = $post['address'] ?? '';
  301. $showAddress = $post['showAddress'] ?? '';
  302. $userAddress = $city . $dist . $address . "({$showAddress})";
  303. $main = $this->main;
  304. $shop = $this->shop;
  305. $shopLat = $shop->lat ?? '';
  306. $shopLong = $shop->long ?? '';
  307. if (empty($shopLat) || empty($shopLong)) {
  308. util::fail('商家门店地址定位未设置,编号263');
  309. }
  310. $wxStoreId = $main->wxStoreId ?? 0;
  311. if (empty($wxStoreId)) {
  312. util::fail('商家还没有开通跑腿功能');
  313. }
  314. $orderData = [
  315. 'wx_store_id' => $wxStoreId,
  316. 'user_name' => $customName,
  317. 'user_phone' => $customMobile,
  318. 'user_lng' => $originalLng,
  319. 'user_lat' => $originalLat,
  320. 'user_address' => $userAddress,
  321. 'cargo' => $cargo,
  322. ];
  323. //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  324. $result = IntraCityExpress::preAddOrder($orderData);
  325. $errCode = $result['errcode'] ?? 1;
  326. if ($errCode != 0) {
  327. $errMsg = $result['errmsg'] ?? '';
  328. util::fail('获取运费错误:' . $errMsg);
  329. }
  330. $fee = $result['est_fee'] ?? 0;
  331. $distance = $result['distance'] ?? 0;
  332. $sendCost = bcdiv($fee, 100, 2);
  333. $post['sendCost'] = $sendCost;
  334. $post['sendDistance'] = $distance;
  335. noticeUtil::push("运费:{$sendCost} 重量:{$totalWeight} 距离:{$distance} 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$modifyPrice} 数量:{$totalNum}", '15280215347');
  336. $modifyPrice = bcadd($modifyPrice, $sendCost, 2);
  337. }
  338. $post['modifyPrice'] = $modifyPrice;
  339. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  340. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  341. if (isset($return->shopId)) {
  342. if ($return->shopId == 7610) {
  343. if ($return->actPrice < 200) {
  344. if ($return->sendType == 0) {
  345. util::fail('满200元支持送货上门');
  346. }
  347. }
  348. }
  349. }
  350. if ($return->sendType == 2) {
  351. if (in_array($return->shopId, [2, 726, 1490, 13626, 7856, 7688])) {
  352. util::fail('暂时不能使用跑腿');
  353. }
  354. }
  355. $transaction->commit();
  356. $orderSn = $return->orderSn ?? '';
  357. $orderPrice = $return->orderPrice ?? 0;
  358. $id = $return->id ?? 0;
  359. $getPayType = dict::getDict('getPayType');
  360. util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id, 'getPayType' => $getPayType]);
  361. } catch (\Exception $e) {
  362. $transaction->rollBack();
  363. Yii::error("失败原因:" . $e->getMessage());
  364. util::fail('下单失败');
  365. }
  366. }
  367. //商城下单操作 ssh 2019.12.3
  368. public function actionCreateOrder()
  369. {
  370. $post = Yii::$app->request->post();
  371. $goodsId = $post['goodsId'] ?? 0;
  372. $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
  373. $sendType = $post['sendType'] ?? dict::getDict('sendType', 'thirdSend');
  374. if (empty($goodsId)) {
  375. util::fail('请选择商品');
  376. }
  377. $mainId = $this->mainId;
  378. $goodsInfo = GoodsClass::getById($goodsId, true);
  379. if (empty($goodsInfo)) {
  380. util::fail('没有找到商品');
  381. }
  382. if ($goodsInfo->mainId != $mainId) {
  383. util::fail('不是你的商品');
  384. }
  385. $stock = $goodsInfo->stock ?? 0;
  386. if ($stock <= 0) {
  387. util::fail('库存不足');
  388. }
  389. //事务处理
  390. $connection = Yii::$app->db;
  391. $transaction = $connection->beginTransaction();
  392. try {
  393. $custom = $this->custom;
  394. if (empty($custom)) {
  395. util::fail('个人信息缺失');
  396. }
  397. $customId = $custom->id ?? 0;
  398. $hd = $this->hd;
  399. $post['customId'] = $customId;
  400. $customName = $custom->name ?? '';
  401. $post['customName'] = $customName;
  402. $post['customNamePy'] = stringUtil::py($customName);
  403. $post['hdId'] = $hd->id ?? 0;
  404. $post['hdName'] = $hd->name ?? '';
  405. $user = $this->user;
  406. $post['bookName'] = $user->name ?? '';
  407. $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  408. $bookMobile = empty($bookMobile) && !empty($user->mobile) ? $user->mobile : $bookMobile;
  409. $post['bookMobile'] = $bookMobile;
  410. $post['payWay'] = 0;
  411. $shop = $this->shop;
  412. $params = [];
  413. $goodsData = $goodsInfo->attributes;
  414. $ret = \bizHd\goods\classes\GoodsClass::getFinalPrice($goodsData, $shop, $custom, $params);
  415. $unitPrice = $ret['price'] ?? 0;
  416. if ($unitPrice <= 0) {
  417. util::fail('没有价格,不能下单哈');
  418. }
  419. //计算总金额
  420. $goodsPrice = $unitPrice * $goodsNum;
  421. //计算运费
  422. $sendDistance = 0;
  423. $sendCost = 0;
  424. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  425. if (dict::getDict('hasMap') == 0) {
  426. util::fail('不能使用跑腿,请选其它方式');
  427. }
  428. $lat = $post['lat'] ?? '';
  429. $lng = $post['long'] ?? '';
  430. if ((empty($lat) || empty($lng))) { // 当 hasMap 为1时,经纬数据是必要的
  431. util::fail('请填写正确地址');
  432. }
  433. $address = $post['address'] ?? '';
  434. $floor = $post['floor'] ?? '';
  435. $fullAddress = $address . $floor;
  436. $post['fullAddress'] = $fullAddress;
  437. $shopLat = $shop->lat ?? '';
  438. $shopLong = $shop->long ?? '';
  439. if (empty($shopLat) || empty($shopLong)) {
  440. util::fail('商家门店地址定位未设置,编号8966');
  441. }
  442. $weight = $goodsInfo->weight ?? 0;
  443. if ($weight <= 0) {
  444. util::fail('商品没有重量');
  445. }
  446. $totalWeight = bcmul($weight, $goodsNum, 2);
  447. $cargoName = '鲜花'; // 商品名称
  448. $cargo = [
  449. 'cargo_name' => $cargoName, // 商品名称
  450. 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  451. 'cargo_price' => intval($goodsPrice * 100), // 单位:分 -- 把元转换为分
  452. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  453. 'cargo_num' => $goodsNum
  454. ];
  455. $customName = $custom->name;
  456. $customMobile = $custom->mobile;
  457. if (empty($post['long']) || empty($post['lat'])) {
  458. util::fail('位置错误');
  459. }
  460. $originalLng = doubleval($post['long']);
  461. $originalLat = doubleval($post['lat']);
  462. $city = $post['city'] ?? '';
  463. $dist = $post['dist'] ?? '';
  464. $address = $post['address'] ?? '';
  465. $showAddress = $post['showAddress'] ?? '';
  466. $userAddress = $city . $dist . $address . "({$showAddress})";
  467. $main = $this->main;
  468. $shopLat = $shop->lat ?? '';
  469. $shopLong = $shop->long ?? '';
  470. if (empty($shopLat) || empty($shopLong)) {
  471. util::fail('商家门店地址定位未设置,编号6880');
  472. }
  473. $wxStoreId = $main->wxStoreId ?? 0;
  474. if (empty($wxStoreId)) {
  475. util::fail('商家还没有开通跑腿功能');
  476. }
  477. $orderData = [
  478. 'wx_store_id' => $wxStoreId,
  479. 'user_name' => $customName,
  480. 'user_phone' => $customMobile,
  481. 'user_lng' => $originalLng,
  482. 'user_lat' => $originalLat,
  483. 'user_address' => $userAddress,
  484. 'cargo' => $cargo,
  485. ];
  486. //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  487. $result = IntraCityExpress::preAddOrder($orderData);
  488. $errCode = $result['errcode'] ?? 1;
  489. if ($errCode != 0) {
  490. $errMsg = $result['errmsg'] ?? '';
  491. util::fail('获取运费错误:' . $errMsg);
  492. }
  493. $fee = $result['est_fee'] ?? 0;
  494. $sendDistance = $result['distance'] ?? 0;
  495. $sendCost = bcdiv($fee, 100, 2);
  496. //免运费的不收运费
  497. if ($goodsInfo->freightType == 1) {
  498. $sendCost = 0;
  499. }
  500. noticeUtil::push("运费:{$sendCost} 重量:{$totalWeight} 距离:{$sendDistance} 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$goodsPrice} 数量:{$goodsNum}", '15280215347');
  501. }
  502. $post['sendDistance'] = $sendDistance;
  503. $post['sendCost'] = $sendCost;
  504. $post['sjId'] = $this->sjId;
  505. $post['shopId'] = $this->shopId;
  506. $post['mainId'] = $mainId;
  507. $post['userId'] = $this->userId;
  508. if ($goodsInfo->priceType == 0) {
  509. util::fail('没有价格,不能下单');
  510. }
  511. $modifyPrice = stringUtil::calcAdd($sendCost, $goodsPrice);
  512. //非门店订单
  513. $post['store'] = 0;
  514. $post['modifyPrice'] = $modifyPrice;
  515. //非自取订单考虑配送时间
  516. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  517. $sendType = $post['sendType'] ?? 0;
  518. if ($sendType != 1) {
  519. if (empty($post['reachPeriod'])) {
  520. util::fail('请选择配送时间哈');
  521. }
  522. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  523. }
  524. $now = time();
  525. $expireTime = $now + 1800;//订单30分钟后过期
  526. $post['deadline'] = $expireTime;
  527. $orderSn = orderSn::getOrderSn();
  528. $post['orderSn'] = $orderSn;
  529. $post['fromType'] = dict::getDict('fromType', 'mall');
  530. $post['cash'] = 0;
  531. $post['mainId'] = $mainId;
  532. $post['needPrint'] = dict::getDict('needPrint', 'need');
  533. $hasPay = 0;
  534. $product = [['productId' => $goodsId, 'unitType' => 0, 'property' => 0, 'unitPrice' => $unitPrice, 'num' => $goodsNum]];
  535. $post['product'] = $product;
  536. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  537. $orderId = $return->id;
  538. $orderSn = $return->orderSn;
  539. $actPrice = $return->actPrice ?? 0;
  540. $transaction->commit();
  541. util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => 0, 'id' => $orderId]);
  542. } catch (Exception $e) {
  543. $transaction->rollBack();
  544. Yii::info("失败原因:" . $e->getMessage());
  545. util::fail('下单失败');
  546. }
  547. }
  548. //下单要用到的相关信息 ssh 2019.12.6
  549. public function actionOrderRelate()
  550. {
  551. $regionTree = RegionService::tree();
  552. //门店名称
  553. $shop = !empty($this->shop) ? $this->shop->attributes : [];
  554. $sjName = $shop['merchantName'] ?? '';
  555. $shopName = $shop['shopName'] ?? '';
  556. $shop['showName'] = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  557. $avatar = $shop['avatar'] ?? '';
  558. $smallAvatar = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  559. $shop['smallAvatar'] = $smallAvatar;
  560. $freight = ['first' => 5, 'add' => 2];
  561. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  562. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  563. util::success($out);
  564. }
  565. //余额支付 ssh 20250410
  566. public function actionBalancePay()
  567. {
  568. $post = Yii::$app->request->post();
  569. $orderSn = $post['orderSn'] ?? '';
  570. //避免重复提交
  571. util::checkRepeatCommit($orderSn, 5);
  572. $connection = Yii::$app->db;
  573. $transaction = $connection->beginTransaction();
  574. try {
  575. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  576. if (empty($order)) {
  577. util::fail('没有找到订单');
  578. }
  579. if ($order->shopId != $this->shopId) {
  580. util::fail('不是你的订单');
  581. }
  582. $payWay = dict::getDict('payWay', 'balancePay');
  583. \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
  584. $transaction->commit();
  585. //解决重复通知,重要
  586. $cacheKey = 'mall_order_balance_pay_' . $orderSn;
  587. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  588. if (empty($has)) {
  589. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  590. //打印小票和语音播报
  591. $order = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  592. \bizHd\order\classes\OrderClass::onlinePrint($order);
  593. $shopId = $order->shopId ?? 0;
  594. $shop = ShopClass::getById($shopId, true);
  595. if (in_array($order->fromType, [1, 3])) {
  596. //您有新的收入提醒
  597. WxMessageClass::gatheringIncomeInform($shop, $order);
  598. }
  599. if ($order->fromType == 2) {
  600. //来自商城的新订单微信通知
  601. WxMessageClass::hdNewOrderInform($shop, $order);
  602. }
  603. }
  604. util::complete('支付成功');
  605. } catch (\Exception $e) {
  606. $transaction->rollBack();
  607. Yii::error("支付原因:" . $e->getMessage());
  608. util::fail('支付失败');
  609. }
  610. }
  611. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  612. public function actionWxPay()
  613. {
  614. ini_set('date.timezone', 'Asia/Shanghai');
  615. $post = Yii::$app->request->post();
  616. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  617. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  618. $order = OrderService::getByOrderSn($orderSn);
  619. $orderId = $order['id'];
  620. //验证优惠券是否还有效
  621. if (!empty($couponId)) {
  622. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  623. }
  624. //支付前验证订单有效性
  625. OrderService::checkBeforePay($order);
  626. $name = !empty($order['orderName']) ? $order['orderName'] : '购买花材';
  627. $shop = $this->shop;
  628. if (empty($shop)) {
  629. util::fail('没有找到门店信息');
  630. }
  631. if (isset($shop->shopName) && !empty($shop->shopName)) {
  632. $name .= '(' . $shop->shopName . ')';
  633. }
  634. $totalFee = $order['mainPay'];
  635. $openId = '';
  636. if (!empty($post['miniOpenId'])) {
  637. $openId = $post['miniOpenId'];
  638. //noticeUtil::push('散客买花时,通过前端获取了openId:' . $openId, '15280215347');
  639. }
  640. if (empty($openId)) {
  641. if (isset($this->user['miniOpenId']) && !empty($this->user['miniOpenId'])) {
  642. $openId = $this->user['miniOpenId'];
  643. //noticeUtil::push('散客买花时,通过数据库获取了openId:' . $openId, '15280215347');
  644. }
  645. }
  646. if (empty($openId)) {
  647. util::fail('没有找到openId');
  648. }
  649. $now = time();
  650. $expireTime = $now + 1800;
  651. $updateData = [];
  652. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  653. $oldOrderSn = $orderSn;
  654. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  655. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  656. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  657. $params = [
  658. 'appid' => 'OP00002119',
  659. 'serial_no' => '018b08cfddbd',
  660. 'merchant_no' => $shop->lklSjNo,
  661. 'term_no' => $shop->lklScanTermNo,
  662. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  663. 'lklCertificatePath' => $lklCertificatePath,
  664. ];
  665. $laResource = new Lakala($params);
  666. $closeParams = [
  667. 'orderSn' => $oldOrderSn,
  668. ];
  669. $response = $laResource->close($closeParams);
  670. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  671. $msg = $response['msg'] ?? '';
  672. $lklSjNo = $shop->lklSjNo ?? '';
  673. noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . '。商户号:' . $lklSjNo, '15280215347');
  674. util::fail('出错了哦,请重新下一单');
  675. }
  676. $orderSn = orderSn::getOrderSn();
  677. $updateData['orderSn'] = $orderSn;
  678. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  679. } else {
  680. //已请求的不能再修改价格
  681. $updateData['modPrice'] = 0;
  682. }
  683. if (empty($order['deadline'])) {
  684. $updateData['deadline'] = $expireTime;
  685. }
  686. if (!empty($updateData)) {
  687. OrderService::updateById($orderId, $updateData);
  688. }
  689. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  690. $sjExtend = WxOpenClass::getMallWxInfo();
  691. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  692. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  693. $params = [
  694. 'appid' => 'OP00002119',
  695. 'serial_no' => '018b08cfddbd',
  696. 'merchant_no' => $shop->lklSjNo,
  697. 'term_no' => $shop->lklScanTermNo,
  698. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  699. 'lklCertificatePath' => $lklCertificatePath,
  700. ];
  701. $laResource = new Lakala($params);
  702. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  703. $wxParams = [
  704. 'orderSn' => $orderSn,
  705. 'amount' => $totalFee,
  706. 'capitalType' => $capitalType,
  707. 'notifyUrl' => $notifyUrl,
  708. 'wxAppId' => $sjExtend['miniAppId'],
  709. 'openId' => $openId,
  710. 'subject' => $name,
  711. 'couponId' => $couponId,
  712. ];
  713. $response = $laResource->driveWxPay($wxParams);
  714. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  715. $errMsg = $response['msg'] ?? '';
  716. noticeUtil::push($errMsg, '15280215347');
  717. util::fail('支付失败');
  718. }
  719. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  720. $appId = $newParams['app_id'] ?? '';
  721. $nonceStr = $newParams['nonce_str'] ?? '';
  722. $paySign = $newParams['pay_sign'] ?? '';
  723. $package = $newParams['package'] ?? '';
  724. $signType = $newParams['sign_type'] ?? '';
  725. $timeStamp = $newParams['time_stamp'] ?? '';
  726. $new = [
  727. 'id' => $orderId,
  728. 'appId' => $appId,
  729. 'nonceStr' => $nonceStr,
  730. 'paySign' => $paySign,
  731. 'package' => $package,
  732. 'signType' => $signType,
  733. 'timeStamp' => $timeStamp,
  734. 'orderSn' => $orderSn,
  735. ];
  736. util::success($new);
  737. }
  738. //快捷付款订单
  739. public function actionFastPay()
  740. {
  741. ini_set('date.timezone', 'Asia/Shanghai');
  742. $post = Yii::$app->request->post();
  743. $payWay = $post['payWay'] ?? 0;
  744. $shopId = $this->shopId;
  745. $shop = $this->shop;
  746. if (empty($shop)) {
  747. util::fail('没有门店信息');
  748. }
  749. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  750. $gatheringItem = !empty($ext) ? $ext->gatheringItem : 0;
  751. if (empty($gatheringItem)) {
  752. util::fail('请设置付款用的商品');
  753. }
  754. $gatheringItemInfo = ItemClass::getById($gatheringItem, true);
  755. if (empty($gatheringItemInfo)) {
  756. util::fail('付款用的商品没有设置');
  757. }
  758. $ptItemId = $gatheringItemInfo->itemId ?? 0;
  759. $classId = $gatheringItemInfo->classId ?? 0;
  760. //收款码是否算收入由ext gatherRepeat决定
  761. $post['repeat'] = $ext->gatherRepeat ?? 0;
  762. $customId = $this->customId;
  763. $custom = $this->custom;
  764. $hdId = $this->hdId;
  765. $hd = $this->hd;
  766. if (empty($customId) || empty($hdId)) {
  767. //考虑没有登录时的付款
  768. $shop = $this->shop;
  769. $defaultCustomId = $shop->defaultCustomId ?? 0;
  770. if (empty($defaultCustomId)) {
  771. util::fail('请设置快捷开单的客户');
  772. }
  773. $customId = $defaultCustomId;
  774. $custom = CustomClass::getById($defaultCustomId, true);
  775. if (empty($custom)) {
  776. util::fail('请设置快捷客户');
  777. }
  778. $hdId = $custom->hdId;
  779. $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
  780. if (empty($hd)) {
  781. util::fail('没有花店信息呢!');
  782. }
  783. }
  784. $post['hdId'] = $hdId;
  785. $post['hdName'] = $hd->name ?? '';
  786. $customName = $custom->name ?? '';
  787. $customPy = $custom->py ?? '';
  788. $post['customName'] = $customName;
  789. $post['customNamePy'] = $customPy;
  790. $post['gatheringItem'] = $gatheringItem;
  791. $post['shopId'] = $shopId;
  792. $post['mainId'] = $this->mainId;
  793. $post['sjId'] = $this->sjId;
  794. $post['store'] = 0;
  795. $post['customId'] = $customId;
  796. $user = $this->user->attributes ?? [];
  797. $post['bookName'] = $user['userName'] ?? '';
  798. $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  799. $bookMobile = empty($bookMobile) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
  800. $post['bookMobile'] = $bookMobile;
  801. $prePrice = round($post['prePrice'], 2);
  802. $couponId = $post['couponId'] ?? 0;
  803. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => 0, 'couponId' => $couponId, 'userId' => $this->userId]);
  804. $actPrice = $discountData['price'];
  805. $post['discountType'] = $discountData['discountType'];
  806. $post['discountAmount'] = $discountData['discountAmount'];
  807. $post['orderPrice'] = $actPrice;
  808. $post['actPrice'] = $actPrice;
  809. $post['realPrice'] = $actPrice;
  810. $post['mainPay'] = $actPrice;
  811. $post['modifyPrice'] = $actPrice;
  812. $post['userId'] = $this->userId;
  813. $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
  814. $now = time();
  815. $expireTime = $now + 300;//订单5分钟后过期
  816. $post['createTime'] = date("Y-m-d H:i:s", $now);
  817. $post['deadline'] = $expireTime;
  818. if ($actPrice <= 0) {
  819. util::fail('请填写付款金额');
  820. }
  821. $post['goodsNum'] = 1;
  822. $product = [[
  823. 'productId' => $gatheringItem,
  824. 'bigNum' => 1,
  825. 'smallNum' => '',
  826. 'num' => 1,
  827. 'unitType' => 0,
  828. 'property' => 1,
  829. 'unitPrice' => $actPrice,
  830. 'itemId' => $ptItemId,
  831. 'classId' => $classId
  832. ]];
  833. $post['product'] = $product;
  834. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : '00-00-00';
  835. $post['onlinePay'] = dict::getDict('onlinePay', 'yes');
  836. //前端未修改时这边做兼容
  837. if (!empty($post['receiveAddress'])) {
  838. $post['address'] = $post['receiveAddress'];
  839. if (!empty($post['receiveProvince'])) {
  840. $post['province'] = $post['receiveProvince'];
  841. }
  842. if (!empty($post['receiveCity'])) {
  843. $post['city'] = $post['receiveCity'];
  844. }
  845. if (!empty($post['receiveFloor'])) {
  846. $post['floor'] = $post['receiveFloor'];
  847. }
  848. if (!empty($post['latitude'])) {
  849. $post['lat'] = $post['latitude'];
  850. }
  851. if (!empty($post['longitude'])) {
  852. $post['long'] = $post['longitude'];
  853. }
  854. $city = $post['receiveCity'] ?? '';
  855. $address = $post['receiveAddress'];
  856. $floor = $post['receiveFloor'] ?? '';
  857. $post['fullAddress'] = $city . $address . $floor;
  858. }
  859. $hasPay = 0;
  860. $post['sendType'] = 1;
  861. $post['orderType'] = 2;//花材订单
  862. $post['dealPrice'] = 1;
  863. $post['fromType'] = 1;
  864. $order = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  865. $orderId = $order->id ?? 0;
  866. $orderSn = $order->orderSn ?? '';
  867. if ($payWay == 0) {
  868. //微信
  869. $name = '购买商品';
  870. $totalFee = $actPrice;
  871. $user = UserService::getById($this->userId);
  872. //小程序使用miniOpenId
  873. $openId = $user['miniOpenId'];
  874. if (empty($openId)) {
  875. $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
  876. }
  877. if (empty($openId)) {
  878. util::fail('没有微信信息');
  879. }
  880. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  881. $sjExtend = WxOpenClass::getMallWxInfo();
  882. $shop = $this->shop;
  883. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  884. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  885. $params = [
  886. 'appid' => 'OP00002119',
  887. 'serial_no' => '018b08cfddbd',
  888. 'merchant_no' => $shop->lklSjNo,
  889. 'term_no' => $shop->lklScanTermNo,
  890. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  891. 'lklCertificatePath' => $lklCertificatePath,
  892. ];
  893. $laResource = new Lakala($params);
  894. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  895. $wxParams = [
  896. 'orderSn' => $orderSn,
  897. 'amount' => $totalFee,
  898. 'capitalType' => $capitalType,
  899. 'notifyUrl' => $notifyUrl,
  900. 'wxAppId' => $sjExtend['miniAppId'],
  901. 'openId' => $openId,
  902. 'subject' => $name,
  903. 'couponId' => $couponId,
  904. ];
  905. $response = $laResource->driveWxPay($wxParams);
  906. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  907. $errMsg = $response['msg'] ?? '';
  908. noticeUtil::push($errMsg, '15280215347');
  909. util::fail('支付失败');
  910. }
  911. $newParams = $response['resp_data']['acc_resp_fields'] ?? [];
  912. $appId = $newParams['app_id'] ?? '';
  913. $nonceStr = $newParams['nonce_str'] ?? '';
  914. $paySign = $newParams['pay_sign'] ?? '';
  915. $package = $newParams['package'] ?? '';
  916. $signType = $newParams['sign_type'] ?? '';
  917. $timeStamp = $newParams['time_stamp'] ?? '';
  918. $new = [
  919. 'id' => $orderId,
  920. 'appId' => $appId,
  921. 'nonceStr' => $nonceStr,
  922. 'paySign' => $paySign,
  923. 'package' => $package,
  924. 'signType' => $signType,
  925. 'timeStamp' => $timeStamp,
  926. 'orderSn' => $orderSn,
  927. ];
  928. util::success($new);
  929. } elseif ($payWay == 1) {
  930. //支付宝
  931. $totalFee = $actPrice;
  932. $subject = '购买花材';
  933. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  934. $shop = $this->shop;
  935. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  936. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  937. $params = [
  938. 'appid' => 'OP00002119',
  939. 'serial_no' => '018b08cfddbd',
  940. 'merchant_no' => $shop->lklSjNo,
  941. 'term_no' => $shop->lklB2BTermNo,
  942. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  943. 'lklCertificatePath' => $lklCertificatePath,
  944. ];
  945. $laResource = new Lakala($params);
  946. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
  947. $cashParams = [
  948. 'orderSn' => $orderSn,
  949. 'amount' => $totalFee,
  950. 'capitalType' => $capitalType,
  951. 'notifyUrl' => $notifyUrl,
  952. 'subject' => $subject,
  953. ];
  954. $response = $laResource->cashierPay($cashParams);
  955. if (!isset($response['code']) || $response['code'] != '000000') {
  956. util::fail('支付失败了');
  957. }
  958. $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  959. if (empty($url)) {
  960. util::fail('支付失败');
  961. }
  962. util::success(['url' => $url]);
  963. } elseif ($payWay == 2) {
  964. util::fail('无效的支付方式');
  965. //余额支付,验证支付密码是否正确
  966. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  967. $user = UserService::getUserInfo($this->userId);
  968. UserService::validPayPassword($payPassword, $user);
  969. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  970. $callbackParams = [];
  971. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  972. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  973. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  974. } else {
  975. util::fail('无效的支付方式');
  976. }
  977. }
  978. //订单列表 ssh 2019.12.12
  979. public function actionList()
  980. {
  981. $get = Yii::$app->request->get();
  982. $status = $get['status'] ?? 0;
  983. $userId = $this->userId;
  984. $where = ['userId' => $userId];
  985. if (!empty($status)) {
  986. $where['status'] = $status;
  987. }
  988. $list = OrderService::getOrderList($where);
  989. util::success($list);
  990. }
  991. //订单评价
  992. public function actionComment()
  993. {
  994. $post = Yii::$app->request->post();
  995. $id = $post['id'];
  996. $order = OrderClass::getById($id);
  997. if ($order['grade'] > 0) {
  998. util::fail('您已经评过了');
  999. }
  1000. OrderService::comment($post);
  1001. util::complete('提交成功');
  1002. }
  1003. //订单详情 ssh 2019.12.16
  1004. public function actionDetail()
  1005. {
  1006. $id = Yii::$app->request->get('id', 0);
  1007. $detail = OrderClass::getOrderById($id);
  1008. $userId = $this->userId;
  1009. if ($detail['userId'] != $userId) {
  1010. util::fail('不是你的单,不能查看');
  1011. }
  1012. $shOrderMap = [];
  1013. if ($detail['hasForward'] == 1) {
  1014. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1015. }
  1016. $detail['shOrderMap'] = $shOrderMap;
  1017. util::success($detail);
  1018. }
  1019. //获取详情 ssh 20220512
  1020. public function actionInfo()
  1021. {
  1022. $sn = Yii::$app->request->get('orderSn', '');
  1023. $detail = OrderClass::getOrderBySn($sn);
  1024. util::success($detail);
  1025. }
  1026. }