OrderController.php 48 KB

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