OrderController.php 49 KB

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