OrderController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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. $priceType = $ret['priceType'] ?? 0;
  416. if ($priceType == 0) {
  417. util::fail('没有价格,不能下单哈');
  418. }
  419. $unitPrice = $ret['price'] ?? 0;
  420. if ($unitPrice <= 0) {
  421. util::fail('没有价格,不能下单呢');
  422. }
  423. //计算总金额
  424. $goodsPrice = $unitPrice * $goodsNum;
  425. //计算运费
  426. $sendDistance = 0;
  427. $sendCost = 0;
  428. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  429. if (dict::getDict('hasMap') == 0) {
  430. util::fail('不能使用跑腿,请选其它方式');
  431. }
  432. $lat = $post['lat'] ?? '';
  433. $lng = $post['long'] ?? '';
  434. if ((empty($lat) || empty($lng))) { // 当 hasMap 为1时,经纬数据是必要的
  435. util::fail('请填写正确地址');
  436. }
  437. $address = $post['address'] ?? '';
  438. $floor = $post['floor'] ?? '';
  439. $fullAddress = $address . $floor;
  440. $post['fullAddress'] = $fullAddress;
  441. $shopLat = $shop->lat ?? '';
  442. $shopLong = $shop->long ?? '';
  443. if (empty($shopLat) || empty($shopLong)) {
  444. util::fail('商家门店地址定位未设置,编号8966');
  445. }
  446. $weight = $goodsInfo->weight ?? 0;
  447. if ($weight <= 0) {
  448. util::fail('商品没有重量');
  449. }
  450. $totalWeight = bcmul($weight, $goodsNum, 2);
  451. $cargoName = '鲜花'; // 商品名称
  452. $cargo = [
  453. 'cargo_name' => $cargoName, // 商品名称
  454. 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  455. 'cargo_price' => intval($goodsPrice * 100), // 单位:分 -- 把元转换为分
  456. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  457. 'cargo_num' => $goodsNum
  458. ];
  459. $customName = $custom->name;
  460. $customMobile = $custom->mobile;
  461. if (empty($post['long']) || empty($post['lat'])) {
  462. util::fail('位置错误');
  463. }
  464. $originalLng = doubleval($post['long']);
  465. $originalLat = doubleval($post['lat']);
  466. $city = $post['city'] ?? '';
  467. $dist = $post['dist'] ?? '';
  468. $address = $post['address'] ?? '';
  469. $showAddress = $post['showAddress'] ?? '';
  470. $userAddress = $city . $dist . $address . "({$showAddress})";
  471. $main = $this->main;
  472. $shopLat = $shop->lat ?? '';
  473. $shopLong = $shop->long ?? '';
  474. if (empty($shopLat) || empty($shopLong)) {
  475. util::fail('商家门店地址定位未设置,编号6880');
  476. }
  477. $wxStoreId = $main->wxStoreId ?? 0;
  478. if (empty($wxStoreId)) {
  479. util::fail('商家还没有开通跑腿功能');
  480. }
  481. $orderData = [
  482. 'wx_store_id' => $wxStoreId,
  483. 'user_name' => $customName,
  484. 'user_phone' => $customMobile,
  485. 'user_lng' => $originalLng,
  486. 'user_lat' => $originalLat,
  487. 'user_address' => $userAddress,
  488. 'cargo' => $cargo,
  489. ];
  490. //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  491. $result = IntraCityExpress::preAddOrder($orderData);
  492. $errCode = $result['errcode'] ?? 1;
  493. if ($errCode != 0) {
  494. $errMsg = $result['errmsg'] ?? '';
  495. util::fail('获取运费错误:' . $errMsg);
  496. }
  497. $fee = $result['est_fee'] ?? 0;
  498. $sendDistance = $result['distance'] ?? 0;
  499. $sendCost = bcdiv($fee, 100, 2);
  500. //免运费的不收运费
  501. if ($goodsInfo->freightType == 1) {
  502. $sendCost = 0;
  503. }
  504. noticeUtil::push("运费:{$sendCost} 重量:{$totalWeight} 距离:{$sendDistance} 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$goodsPrice} 数量:{$goodsNum}", '15280215347');
  505. }
  506. $post['sendDistance'] = $sendDistance;
  507. $post['sendCost'] = $sendCost;
  508. $post['sjId'] = $this->sjId;
  509. $post['shopId'] = $this->shopId;
  510. $post['mainId'] = $mainId;
  511. $post['userId'] = $this->userId;
  512. if ($goodsInfo->priceType == 0) {
  513. util::fail('没有价格,不能下单');
  514. }
  515. $modifyPrice = stringUtil::calcAdd($sendCost, $goodsPrice);
  516. //非门店订单
  517. $post['store'] = 0;
  518. $post['modifyPrice'] = $modifyPrice;
  519. //非自取订单考虑配送时间
  520. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  521. $sendType = $post['sendType'] ?? 0;
  522. if ($sendType != 1) {
  523. if (empty($post['reachPeriod'])) {
  524. util::fail('请选择配送时间哈');
  525. }
  526. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  527. }
  528. $now = time();
  529. $expireTime = $now + 1800;//订单30分钟后过期
  530. $post['deadline'] = $expireTime;
  531. $orderSn = orderSn::getOrderSn();
  532. $post['orderSn'] = $orderSn;
  533. $post['fromType'] = dict::getDict('fromType', 'mall');
  534. $post['cash'] = 0;
  535. $post['mainId'] = $mainId;
  536. $post['needPrint'] = dict::getDict('needPrint', 'need');
  537. $hasPay = 0;
  538. $product = [['productId' => $goodsId, 'unitType' => 0, 'property' => 0, 'unitPrice' => $unitPrice, 'num' => $goodsNum]];
  539. $post['product'] = $product;
  540. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  541. $orderId = $return->id;
  542. $orderSn = $return->orderSn;
  543. $actPrice = $return->actPrice ?? 0;
  544. $transaction->commit();
  545. util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => 0, 'id' => $orderId]);
  546. } catch (Exception $e) {
  547. $transaction->rollBack();
  548. Yii::info("失败原因:" . $e->getMessage());
  549. util::fail('下单失败');
  550. }
  551. }
  552. //下单要用到的相关信息 ssh 2019.12.6
  553. public function actionOrderRelate()
  554. {
  555. $regionTree = RegionService::tree();
  556. //门店名称
  557. $shop = !empty($this->shop) ? $this->shop->attributes : [];
  558. $sjName = $shop['merchantName'] ?? '';
  559. $shopName = $shop['shopName'] ?? '';
  560. $shop['showName'] = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  561. $avatar = $shop['avatar'] ?? '';
  562. $smallAvatar = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  563. $shop['smallAvatar'] = $smallAvatar;
  564. $freight = ['first' => 5, 'add' => 2];
  565. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  566. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  567. util::success($out);
  568. }
  569. //余额支付 ssh 20250410
  570. public function actionBalancePay()
  571. {
  572. $post = Yii::$app->request->post();
  573. $orderSn = $post['orderSn'] ?? '';
  574. //避免重复提交
  575. util::checkRepeatCommit($orderSn, 5);
  576. $connection = Yii::$app->db;
  577. $transaction = $connection->beginTransaction();
  578. try {
  579. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  580. if (empty($order)) {
  581. util::fail('没有找到订单');
  582. }
  583. if ($order->shopId != $this->shopId) {
  584. util::fail('不是你的订单');
  585. }
  586. $payWay = dict::getDict('payWay', 'balancePay');
  587. \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
  588. $transaction->commit();
  589. //解决重复通知,重要
  590. $cacheKey = 'mall_order_balance_pay_' . $orderSn;
  591. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  592. if (empty($has)) {
  593. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  594. //打印小票和语音播报
  595. $order = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  596. \bizHd\order\classes\OrderClass::onlinePrint($order);
  597. $shopId = $order->shopId ?? 0;
  598. $shop = ShopClass::getById($shopId, true);
  599. if (in_array($order->fromType, [1, 3])) {
  600. //您有新的收入提醒
  601. WxMessageClass::gatheringIncomeInform($shop, $order);
  602. }
  603. if ($order->fromType == 2) {
  604. //来自商城的新订单微信通知
  605. WxMessageClass::hdNewOrderInform($shop, $order);
  606. }
  607. }
  608. util::complete('支付成功');
  609. } catch (\Exception $e) {
  610. $transaction->rollBack();
  611. Yii::error("支付原因:" . $e->getMessage());
  612. util::fail('支付失败');
  613. }
  614. }
  615. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  616. public function actionWxPay()
  617. {
  618. ini_set('date.timezone', 'Asia/Shanghai');
  619. $post = Yii::$app->request->post();
  620. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  621. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  622. $order = OrderService::getByOrderSn($orderSn);
  623. $orderId = $order['id'];
  624. //验证优惠券是否还有效
  625. if (!empty($couponId)) {
  626. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  627. }
  628. //支付前验证订单有效性
  629. OrderService::checkBeforePay($order);
  630. $name = !empty($order['orderName']) ? $order['orderName'] : '购买花材';
  631. $shop = $this->shop;
  632. if (empty($shop)) {
  633. util::fail('没有找到门店信息');
  634. }
  635. if (isset($shop->shopName) && !empty($shop->shopName)) {
  636. $name .= '(' . $shop->shopName . ')';
  637. }
  638. $totalFee = $order['mainPay'];
  639. $openId = '';
  640. if (!empty($post['miniOpenId'])) {
  641. $openId = $post['miniOpenId'];
  642. //noticeUtil::push('散客买花时,通过前端获取了openId:' . $openId, '15280215347');
  643. }
  644. if (empty($openId)) {
  645. if (isset($this->user['miniOpenId']) && !empty($this->user['miniOpenId'])) {
  646. $openId = $this->user['miniOpenId'];
  647. //noticeUtil::push('散客买花时,通过数据库获取了openId:' . $openId, '15280215347');
  648. }
  649. }
  650. if (empty($openId)) {
  651. util::fail('没有找到openId');
  652. }
  653. $now = time();
  654. $expireTime = $now + 1800;
  655. $updateData = [];
  656. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  657. $oldOrderSn = $orderSn;
  658. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  659. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  660. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  661. $params = [
  662. 'appid' => 'OP00002119',
  663. 'serial_no' => '018b08cfddbd',
  664. 'merchant_no' => $shop->lklSjNo,
  665. 'term_no' => $shop->lklScanTermNo,
  666. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  667. 'lklCertificatePath' => $lklCertificatePath,
  668. ];
  669. $laResource = new Lakala($params);
  670. $closeParams = [
  671. 'orderSn' => $oldOrderSn,
  672. ];
  673. $response = $laResource->close($closeParams);
  674. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  675. $msg = $response['msg'] ?? '';
  676. $lklSjNo = $shop->lklSjNo ?? '';
  677. noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . '。商户号:' . $lklSjNo, '15280215347');
  678. util::fail('出错了哦,请重新下一单');
  679. }
  680. $orderSn = orderSn::getOrderSn();
  681. $updateData['orderSn'] = $orderSn;
  682. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  683. } else {
  684. //已请求的不能再修改价格
  685. $updateData['modPrice'] = 0;
  686. }
  687. if (empty($order['deadline'])) {
  688. $updateData['deadline'] = $expireTime;
  689. }
  690. if (!empty($updateData)) {
  691. OrderService::updateById($orderId, $updateData);
  692. }
  693. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  694. $sjExtend = WxOpenClass::getMallWxInfo();
  695. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  696. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  697. $params = [
  698. 'appid' => 'OP00002119',
  699. 'serial_no' => '018b08cfddbd',
  700. 'merchant_no' => $shop->lklSjNo,
  701. 'term_no' => $shop->lklScanTermNo,
  702. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  703. 'lklCertificatePath' => $lklCertificatePath,
  704. ];
  705. $laResource = new Lakala($params);
  706. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  707. $wxParams = [
  708. 'orderSn' => $orderSn,
  709. 'amount' => $totalFee,
  710. 'capitalType' => $capitalType,
  711. 'notifyUrl' => $notifyUrl,
  712. 'wxAppId' => $sjExtend['miniAppId'],
  713. 'openId' => $openId,
  714. 'subject' => $name,
  715. 'couponId' => $couponId,
  716. ];
  717. $response = $laResource->driveWxPay($wxParams);
  718. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  719. $errMsg = $response['msg'] ?? '';
  720. noticeUtil::push($errMsg, '15280215347');
  721. util::fail('支付失败');
  722. }
  723. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  724. $appId = $newParams['app_id'] ?? '';
  725. $nonceStr = $newParams['nonce_str'] ?? '';
  726. $paySign = $newParams['pay_sign'] ?? '';
  727. $package = $newParams['package'] ?? '';
  728. $signType = $newParams['sign_type'] ?? '';
  729. $timeStamp = $newParams['time_stamp'] ?? '';
  730. $new = [
  731. 'id' => $orderId,
  732. 'appId' => $appId,
  733. 'nonceStr' => $nonceStr,
  734. 'paySign' => $paySign,
  735. 'package' => $package,
  736. 'signType' => $signType,
  737. 'timeStamp' => $timeStamp,
  738. 'orderSn' => $orderSn,
  739. ];
  740. util::success($new);
  741. }
  742. //快捷付款订单
  743. public function actionFastPay()
  744. {
  745. ini_set('date.timezone', 'Asia/Shanghai');
  746. $post = Yii::$app->request->post();
  747. $payWay = $post['payWay'] ?? 0;
  748. $shopId = $this->shopId;
  749. $shop = $this->shop;
  750. if (empty($shop)) {
  751. util::fail('没有门店信息');
  752. }
  753. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  754. $gatheringItem = !empty($ext) ? $ext->gatheringItem : 0;
  755. if (empty($gatheringItem)) {
  756. util::fail('请设置付款用的商品');
  757. }
  758. $gatheringItemInfo = ItemClass::getById($gatheringItem, true);
  759. if (empty($gatheringItemInfo)) {
  760. util::fail('付款用的商品没有设置');
  761. }
  762. $ptItemId = $gatheringItemInfo->itemId ?? 0;
  763. $classId = $gatheringItemInfo->classId ?? 0;
  764. //收款码是否算收入由ext gatherRepeat决定
  765. $post['repeat'] = $ext->gatherRepeat ?? 0;
  766. $customId = $this->customId;
  767. $custom = $this->custom;
  768. $hdId = $this->hdId;
  769. $hd = $this->hd;
  770. if (empty($customId) || empty($hdId)) {
  771. //考虑没有登录时的付款
  772. $shop = $this->shop;
  773. $defaultCustomId = $shop->defaultCustomId ?? 0;
  774. if (empty($defaultCustomId)) {
  775. util::fail('请设置快捷开单的客户');
  776. }
  777. $customId = $defaultCustomId;
  778. $custom = CustomClass::getById($defaultCustomId, true);
  779. if (empty($custom)) {
  780. util::fail('请设置快捷客户');
  781. }
  782. $hdId = $custom->hdId;
  783. $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
  784. if (empty($hd)) {
  785. util::fail('没有花店信息呢!');
  786. }
  787. }
  788. $post['hdId'] = $hdId;
  789. $post['hdName'] = $hd->name ?? '';
  790. $customName = $custom->name ?? '';
  791. $customPy = $custom->py ?? '';
  792. $post['customName'] = $customName;
  793. $post['customNamePy'] = $customPy;
  794. $post['gatheringItem'] = $gatheringItem;
  795. $post['shopId'] = $shopId;
  796. $post['mainId'] = $this->mainId;
  797. $post['sjId'] = $this->sjId;
  798. $post['store'] = 0;
  799. $post['customId'] = $customId;
  800. $user = $this->user->attributes ?? [];
  801. $post['bookName'] = $user['userName'] ?? '';
  802. $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  803. $bookMobile = empty($bookMobile) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
  804. $post['bookMobile'] = $bookMobile;
  805. $prePrice = round($post['prePrice'], 2);
  806. $couponId = $post['couponId'] ?? 0;
  807. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => 0, 'couponId' => $couponId, 'userId' => $this->userId]);
  808. $actPrice = $discountData['price'];
  809. $post['discountType'] = $discountData['discountType'];
  810. $post['discountAmount'] = $discountData['discountAmount'];
  811. $post['orderPrice'] = $actPrice;
  812. $post['actPrice'] = $actPrice;
  813. $post['realPrice'] = $actPrice;
  814. $post['mainPay'] = $actPrice;
  815. $post['modifyPrice'] = $actPrice;
  816. $post['userId'] = $this->userId;
  817. $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
  818. $now = time();
  819. $expireTime = $now + 300;//订单5分钟后过期
  820. $post['createTime'] = date("Y-m-d H:i:s", $now);
  821. $post['deadline'] = $expireTime;
  822. if ($actPrice <= 0) {
  823. util::fail('请填写付款金额');
  824. }
  825. $post['goodsNum'] = 1;
  826. $product = [[
  827. 'productId' => $gatheringItem,
  828. 'bigNum' => 1,
  829. 'smallNum' => '',
  830. 'num' => 1,
  831. 'unitType' => 0,
  832. 'property' => 1,
  833. 'unitPrice' => $actPrice,
  834. 'itemId' => $ptItemId,
  835. 'classId' => $classId
  836. ]];
  837. $post['product'] = $product;
  838. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : '00-00-00';
  839. $post['onlinePay'] = dict::getDict('onlinePay', 'yes');
  840. //前端未修改时这边做兼容
  841. if (!empty($post['receiveAddress'])) {
  842. $post['address'] = $post['receiveAddress'];
  843. if (!empty($post['receiveProvince'])) {
  844. $post['province'] = $post['receiveProvince'];
  845. }
  846. if (!empty($post['receiveCity'])) {
  847. $post['city'] = $post['receiveCity'];
  848. }
  849. if (!empty($post['receiveFloor'])) {
  850. $post['floor'] = $post['receiveFloor'];
  851. }
  852. if (!empty($post['latitude'])) {
  853. $post['lat'] = $post['latitude'];
  854. }
  855. if (!empty($post['longitude'])) {
  856. $post['long'] = $post['longitude'];
  857. }
  858. $city = $post['receiveCity'] ?? '';
  859. $address = $post['receiveAddress'];
  860. $floor = $post['receiveFloor'] ?? '';
  861. $post['fullAddress'] = $city . $address . $floor;
  862. }
  863. $hasPay = 0;
  864. $post['sendType'] = 1;
  865. $post['orderType'] = 2;//花材订单
  866. $post['dealPrice'] = 1;
  867. $post['fromType'] = 1;
  868. $order = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  869. $orderId = $order->id ?? 0;
  870. $orderSn = $order->orderSn ?? '';
  871. if ($payWay == 0) {
  872. //微信
  873. $name = '购买商品';
  874. $totalFee = $actPrice;
  875. $user = UserService::getById($this->userId);
  876. //小程序使用miniOpenId
  877. $openId = $user['miniOpenId'];
  878. if (empty($openId)) {
  879. $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
  880. }
  881. if (empty($openId)) {
  882. util::fail('没有微信信息');
  883. }
  884. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  885. $sjExtend = WxOpenClass::getMallWxInfo();
  886. $shop = $this->shop;
  887. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  888. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  889. $params = [
  890. 'appid' => 'OP00002119',
  891. 'serial_no' => '018b08cfddbd',
  892. 'merchant_no' => $shop->lklSjNo,
  893. 'term_no' => $shop->lklScanTermNo,
  894. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  895. 'lklCertificatePath' => $lklCertificatePath,
  896. ];
  897. $laResource = new Lakala($params);
  898. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  899. $wxParams = [
  900. 'orderSn' => $orderSn,
  901. 'amount' => $totalFee,
  902. 'capitalType' => $capitalType,
  903. 'notifyUrl' => $notifyUrl,
  904. 'wxAppId' => $sjExtend['miniAppId'],
  905. 'openId' => $openId,
  906. 'subject' => $name,
  907. 'couponId' => $couponId,
  908. ];
  909. $response = $laResource->driveWxPay($wxParams);
  910. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  911. $errMsg = $response['msg'] ?? '';
  912. noticeUtil::push($errMsg, '15280215347');
  913. util::fail('支付失败');
  914. }
  915. $newParams = $response['resp_data']['acc_resp_fields'] ?? [];
  916. $appId = $newParams['app_id'] ?? '';
  917. $nonceStr = $newParams['nonce_str'] ?? '';
  918. $paySign = $newParams['pay_sign'] ?? '';
  919. $package = $newParams['package'] ?? '';
  920. $signType = $newParams['sign_type'] ?? '';
  921. $timeStamp = $newParams['time_stamp'] ?? '';
  922. $new = [
  923. 'id' => $orderId,
  924. 'appId' => $appId,
  925. 'nonceStr' => $nonceStr,
  926. 'paySign' => $paySign,
  927. 'package' => $package,
  928. 'signType' => $signType,
  929. 'timeStamp' => $timeStamp,
  930. 'orderSn' => $orderSn,
  931. ];
  932. util::success($new);
  933. } elseif ($payWay == 1) {
  934. //支付宝
  935. $totalFee = $actPrice;
  936. $subject = '购买花材';
  937. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  938. $shop = $this->shop;
  939. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  940. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  941. $params = [
  942. 'appid' => 'OP00002119',
  943. 'serial_no' => '018b08cfddbd',
  944. 'merchant_no' => $shop->lklSjNo,
  945. 'term_no' => $shop->lklB2BTermNo,
  946. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  947. 'lklCertificatePath' => $lklCertificatePath,
  948. ];
  949. $laResource = new Lakala($params);
  950. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
  951. $cashParams = [
  952. 'orderSn' => $orderSn,
  953. 'amount' => $totalFee,
  954. 'capitalType' => $capitalType,
  955. 'notifyUrl' => $notifyUrl,
  956. 'subject' => $subject,
  957. ];
  958. $response = $laResource->cashierPay($cashParams);
  959. if (!isset($response['code']) || $response['code'] != '000000') {
  960. util::fail('支付失败了');
  961. }
  962. $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  963. if (empty($url)) {
  964. util::fail('支付失败');
  965. }
  966. util::success(['url' => $url]);
  967. } elseif ($payWay == 2) {
  968. util::fail('无效的支付方式');
  969. //余额支付,验证支付密码是否正确
  970. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  971. $user = UserService::getUserInfo($this->userId);
  972. UserService::validPayPassword($payPassword, $user);
  973. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  974. $callbackParams = [];
  975. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  976. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  977. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  978. } else {
  979. util::fail('无效的支付方式');
  980. }
  981. }
  982. //订单列表 ssh 2019.12.12
  983. public function actionList()
  984. {
  985. $get = Yii::$app->request->get();
  986. $status = $get['status'] ?? 0;
  987. $userId = $this->userId;
  988. $where = ['userId' => $userId];
  989. if (!empty($status)) {
  990. $where['status'] = $status;
  991. }
  992. $list = OrderService::getOrderList($where);
  993. util::success($list);
  994. }
  995. //订单评价
  996. public function actionComment()
  997. {
  998. $post = Yii::$app->request->post();
  999. $id = $post['id'];
  1000. $order = OrderClass::getById($id);
  1001. if ($order['grade'] > 0) {
  1002. util::fail('您已经评过了');
  1003. }
  1004. OrderService::comment($post);
  1005. util::complete('提交成功');
  1006. }
  1007. //订单详情 ssh 2019.12.16
  1008. public function actionDetail()
  1009. {
  1010. $id = Yii::$app->request->get('id', 0);
  1011. $detail = OrderClass::getOrderById($id);
  1012. $userId = $this->userId;
  1013. if ($detail['userId'] != $userId) {
  1014. util::fail('不是你的单,不能查看');
  1015. }
  1016. $shOrderMap = [];
  1017. if ($detail['hasForward'] == 1) {
  1018. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1019. }
  1020. $detail['shOrderMap'] = $shOrderMap;
  1021. util::success($detail);
  1022. }
  1023. //获取详情 ssh 20220512
  1024. public function actionInfo()
  1025. {
  1026. $sn = Yii::$app->request->get('orderSn', '');
  1027. $detail = OrderClass::getOrderBySn($sn);
  1028. util::success($detail);
  1029. }
  1030. }