OrderController.php 47 KB

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