OrderController.php 48 KB

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