OrderController.php 46 KB

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