OrderController.php 45 KB

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