OrderController.php 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064
  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\distribution\classes\DistributionOrderClass;
  8. use bizHd\express\classes\HdDeliveryOrderClass;
  9. use bizHd\order\classes\OrderClass as HdOrderClass;
  10. use bizHd\order\classes\PsMethodClass;
  11. use bizHd\refund\classes\MallRefundApplyClass;
  12. use bizHd\hb\classes\HbClass;
  13. use bizHd\hb\classes\HbScopeClass;
  14. use bizHd\homePageConfig\classes\HomePageModuleClass;
  15. use bizHd\order\classes\ScanPayClass;
  16. use bizHd\wx\classes\WxOpenClass;
  17. use bizMall\custom\classes\CustomClass;
  18. use bizMall\goods\classes\GoodsClass;
  19. use bizMall\order\classes\OrderClass;
  20. use bizMall\order\classes\OrderForwardClass;
  21. use bizMall\order\classes\OrderItemClass;
  22. use bizMall\order\services\OrderService;
  23. use bizMall\promote\services\CouponService;
  24. use bizMall\saas\services\RegionService;
  25. use bizMall\shop\classes\ShopExtClass;
  26. use bizMall\user\services\UserService;
  27. use common\components\dateUtil;
  28. use common\components\delivery\util\DeliveryQuoteUtil;
  29. use common\components\dict;
  30. use common\components\imgUtil;
  31. use common\components\mapUtil;
  32. use common\components\noticeUtil;
  33. use common\components\orderSn;
  34. use common\components\stringUtil;
  35. use Yii;
  36. use common\components\util;
  37. use common\components\lakala\Lakala;
  38. use common\components\IntraCityExpress;
  39. class OrderController extends BaseController
  40. {
  41. //二维码收款使用
  42. public $guestAccess = ['order-relate', 'fast-pay'];
  43. public function actionInform()
  44. {
  45. $get = Yii::$app->request->get();
  46. $hdId = $get['hdId'] ?? 0;
  47. $account = $get['account'] ?? 0;
  48. $page = $get['page'] ?? '';
  49. $userId = $this->userId;
  50. noticeUtil::push("零售客户下单报错 hdId:{$hdId} account:{$account} userId:{$userId} page:{$page}", '15280215347');
  51. }
  52. //记账单列表 ssh 20250627
  53. public function actionDebtList()
  54. {
  55. $get = Yii::$app->request->get();
  56. $id = $get['id'] ?? 0;
  57. $where = [];
  58. $where['userId'] = $this->userId;
  59. if (!empty($id)) {
  60. $hd = \bizMall\hd\classes\HdClass::getById($id, true);
  61. if (empty($hd)) {
  62. util::fail('无效的花店');
  63. }
  64. $where['hdId'] = $id;
  65. }
  66. $where['debt'] = 1;
  67. $searchTime = $get['searchTime'] ?? '';
  68. if (!empty($searchTime)) {
  69. $startTime = $get['startTime'] ?? '';
  70. $endTime = $get['endTime'] ?? '';
  71. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  72. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  73. }
  74. $respond = OrderClass::getDebtList($where);
  75. util::success($respond);
  76. }
  77. //新计算运费
  78. public function actionNewFreight()
  79. {
  80. $post = Yii::$app->request->post();
  81. $hasMap = dict::getDict('hasMap');
  82. if ($hasMap == 0) {
  83. util::fail('暂不支持跑腿功能');
  84. }
  85. $mainData = $this->main;
  86. $wxStoreId = $mainData->wxStoreId ?? '';
  87. if (empty($wxStoreId)) {
  88. util::fail('商家还没有开通跑腿');
  89. }
  90. $cargoName = $post['cargo_name']; // 商品名称
  91. $cargo = [
  92. 'cargo_name' => $cargoName, // 商品名称
  93. 'cargo_weight' => intval($post['weight'] * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  94. 'cargo_price' => intval($post['price'] * 100), // 单位:分 -- 把元转换为分
  95. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  96. 'cargo_num' => intval($post['package_num'])
  97. ];
  98. $originalLng = doubleval($post['user_lng']);
  99. $originalLat = doubleval($post['user_lat']);
  100. $userName = !empty($post['user_name']) ? $post['user_name'] : '游客';
  101. $orderData = [
  102. 'wx_store_id' => $wxStoreId,
  103. 'user_name' => $userName,
  104. 'user_phone' => $post['user_phone'],
  105. 'user_lng' => $originalLng,
  106. 'user_lat' => $originalLat,
  107. 'user_address' => $post['user_address'],
  108. 'cargo' => $cargo,
  109. ];
  110. //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  111. $result = IntraCityExpress::preAddOrder($orderData);
  112. if ($result['errcode'] === 0) {
  113. util::success($result, "查询成功");
  114. } else {
  115. Yii::error("运费查询失败:" . json_encode($result));
  116. $errMsg = $result['errmsg'] ?? '';
  117. $errCode = $result['errcode'] ?? '';
  118. noticeUtil::push("运费查询失败,原因:" . $errMsg . ",编号:" . $errCode, '15280215347');
  119. util::fail('运费查询失败,请确认是否超过20公斤,编号896');
  120. }
  121. }
  122. //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
  123. public function actionFreight()
  124. {
  125. $get = Yii::$app->request->get();
  126. $shop = $this->shop;
  127. $shopLat = isset($shop->lat) ? $shop->lat : '';
  128. $shopLong = isset($shop->long) ? $shop->long : '';
  129. // 判断地图功能是否正常。0 表示地图定位不可用,全部经纬度数据失效
  130. if (dict::getDict('hasMap') == 0) {
  131. $shopLat = '';
  132. $shopLong = '';
  133. }
  134. if (empty($shopLat) || empty($shopLong)) {
  135. util::success([
  136. 'distance' => 0,
  137. 'showDistance' => 0,
  138. 'fee' => 0,
  139. 'hasMap' => dict::getDict('hasMap'),
  140. 'shop' => 'fail' //门店引起的失败
  141. ]);
  142. }
  143. $userLat = $get['lat'] ?? '';
  144. $userLong = $get['long'] ?? '';
  145. if (empty($userLat) || empty($userLong)) {
  146. util::success([
  147. 'distance' => 0,
  148. 'showDistance' => 0,
  149. 'fee' => 0,
  150. 'hasMap' => dict::getDict('hasMap'),
  151. 'client' => 'fail' //用户端定位失败
  152. ]);
  153. }
  154. $weight = $get['weight'] ?? 0;
  155. if (empty($weight)) {
  156. util::success([
  157. 'distance' => 0,
  158. 'showDistance' => 0,
  159. 'fee' => 0,
  160. 'hasMap' => dict::getDict('hasMap'),
  161. 'weight' => 'fail' //重量不对
  162. ]);
  163. }
  164. //data: {distance: "321", showDistance: "0.3", fee: "12.00"}
  165. $respond = OrderClass::getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight);
  166. util::success($respond);
  167. }
  168. // 零售商的限购花材信息(与批发端 PurchaseController::actionLimitBuyInfo 对应,按花店客户与 hd_limit_buy Redis)
  169. public function actionLimitBuyInfo()
  170. {
  171. $post = Yii::$app->request->post();
  172. $list = $post['list'] ?? [];
  173. if (empty($list) || !is_array($list)) {
  174. util::fail('请选择花材');
  175. }
  176. $hd = $this->hd;
  177. if (empty($hd)) {
  178. util::fail('没有找到花店');
  179. }
  180. if ($hd->shopId != $this->shopId) {
  181. util::fail('不是你的花店');
  182. }
  183. $hdCustomId = $hd->customId ?? 0;
  184. if (empty($hdCustomId)) {
  185. util::fail('没有找到客户');
  186. }
  187. $respond = \bizHd\product\classes\ProductClass::getLimitBuyInfoByList($list, $hdCustomId);
  188. util::success($respond);
  189. }
  190. //购买花材 ssh 20220511
  191. public function actionBuyItem()
  192. {
  193. $post = Yii::$app->request->post();
  194. $post['sjId'] = $this->sjId;
  195. $post['shopId'] = $this->shopId;
  196. $post['payWay'] = 0;
  197. $post['mainId'] = $this->mainId ?? 0;
  198. $post['userId'] = $this->userId ?? 0;
  199. //避免重复提交
  200. $userId = $this->userId;
  201. util::checkRepeatCommit($userId, 3);
  202. $shop = $this->shop;
  203. $openShop = \bizHd\shop\classes\ShopClass::getOpenShop($shop);
  204. if ($openShop == 0) {
  205. util::fail('已休店');
  206. }
  207. //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
  208. $mainId = $this->mainId;
  209. if (getenv('YII_ENV') == 'production') {
  210. if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) {
  211. util::fail('暂时无法访问');
  212. }
  213. } else {
  214. if (in_array($mainId, [0, 1])) {
  215. util::fail('暂时无法访问');
  216. }
  217. }
  218. $hdId = $post['hdId'] ?? 0;
  219. $hd = HdClass::getById($hdId, true);
  220. if (empty($hd)) {
  221. util::fail('没有找到花店');
  222. }
  223. if ($hd->shopId != $this->shopId) {
  224. util::fail('不是你的花店');
  225. }
  226. $post['hdName'] = $hd->name ?? '';
  227. $hdCustomId = $hd->customId ?? 0;
  228. $custom = CustomClass::getById($hdCustomId, true);
  229. if (empty($custom)) {
  230. util::fail('没有找到客户');
  231. }
  232. $customName = $custom->name ?? '';
  233. $post['customId'] = $hdCustomId;
  234. $post['customName'] = $customName;
  235. $post['customNamePy'] = stringUtil::py($customName);
  236. $now = time();
  237. //订单30分钟后过期
  238. $expireTime = $now + 1800;
  239. $post['deadline'] = $expireTime;
  240. //商城
  241. $post['fromType'] = dict::getDict('fromType', 'mall');
  242. $productJson = $post['product'] ?? '';
  243. if (empty($productJson) && empty($groupId)) {
  244. util::fail('请选择商品');
  245. }
  246. $productList = json_decode($productJson, true);
  247. if (empty($productList)) {
  248. util::fail('请选择商品');
  249. }
  250. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  251. $productInfoList = productClass::getByIds($ids, null, 'id');
  252. if (!empty($productInfoList)) {
  253. $presellData = [];
  254. $nowTime = strtotime(date("Y-m-d"));
  255. foreach ($productInfoList as $currentInfo) {
  256. if (!isset($currentInfo['mainId']) || $currentInfo['mainId'] != $this->mainId) {
  257. util::fail('只能选一家的商品,请清空重新选呢');
  258. }
  259. $presell = $currentInfo['presell'] ?? 0;
  260. $presellData[] = $presell;
  261. if ($presell == 1) {
  262. if (empty($post['reachDate'])) {
  263. util::fail('请选择配送或取货日期');
  264. }
  265. $sendTimeWant = $post['reachDate'];
  266. if (strtotime($sendTimeWant) < $nowTime) {
  267. util::fail('不能选择过去时间');
  268. }
  269. $hasDateStr = $currentInfo['presellDate'] ?? [];
  270. $hasDate = explode(',', trim($hasDateStr));
  271. if (empty($hasDate)) {
  272. util::fail('预售日期有问题,请提醒门店');
  273. }
  274. if (!in_array(strtotime($sendTimeWant), $hasDate)) {
  275. util::fail("有预售花材在{$sendTimeWant}没到货");
  276. }
  277. $post['presell'] = 1;
  278. }
  279. }
  280. if (count($productInfoList) != count($ids)) {
  281. util::fail('存在无效商品');
  282. }
  283. $presellData = array_unique($presellData);
  284. if (count($presellData) > 1) {
  285. util::fail('预售和非预售花材不能一起下单');
  286. }
  287. } else {
  288. util::fail('花材不存在');
  289. }
  290. $connection = Yii::$app->db;
  291. $transaction = $connection->beginTransaction();
  292. $transactionFinished = false;
  293. register_shutdown_function(function () use (&$transactionFinished, $transaction) {
  294. if ($transactionFinished) {
  295. return;
  296. }
  297. \bizHd\product\classes\ProductClass::rollbackLimitBuySnapshot();
  298. if ($transaction->isActive) {
  299. $transaction->rollBack();
  300. }
  301. });
  302. try {
  303. $orderValidTime = !getenv('ORDER_VALID_TIME') ? 600 : getenv('ORDER_VALID_TIME');
  304. $post['deadline'] = time() + $orderValidTime;
  305. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  306. $post['needPrint'] = dict::getDict('needPrint', 'need');
  307. $user = $this->user;
  308. $post['bookMobile'] = $user->mobile ?? '';
  309. $post['bookName'] = $user->name ?? '';
  310. $hasPay = 0;
  311. $modifyPrice = 0;
  312. //各个等级对应的price addPrice字段
  313. $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
  314. $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
  315. $totalWeight = 0;
  316. $totalNum = 0;
  317. $totalReachDiscount = 0;
  318. foreach ($productList as $eleKey => $element) {
  319. $level = 0;
  320. $productId = $element['productId'];
  321. $product = $productInfoList[$productId];
  322. if (empty($product)) {
  323. util::fail('有商品信息没有找到');
  324. }
  325. $num = $element['num'] ?? 0; // 此次购买数量
  326. $limitKey = \bizHd\product\classes\ProductClass::LIMIT_BUY_KEY . $productId;
  327. $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $hdCustomId]);
  328. $hasBuyNum = $num + ($hasBuyNum == null ? 0 : $hasBuyNum); // 已购买总数量
  329. $price = \bizGhs\product\classes\ProductClass::getFinalPrice($product, $level, $priceMap, $addPriceMap, 0, $num, $hasBuyNum);
  330. $reachNum = $product['reachNum'] ?? 0;
  331. $reachNumDiscount = $product['reachNumDiscount'] ?? 0;
  332. if ($reachNum > 0 && $num >= $reachNum && $reachNumDiscount > 0) {
  333. $currentReachDiscount = bcmul($reachNumDiscount, $num, 2);
  334. $totalReachDiscount = bcadd($totalReachDiscount, $currentReachDiscount, 2);
  335. }
  336. $currentTotal = bcmul($price, $num, 2);
  337. $modifyPrice = bcadd($modifyPrice, $currentTotal, 2);
  338. $productList[$eleKey]['unitPrice'] = $price;
  339. $weight = $product['weight'] ?? 0;
  340. $currentWeight = bcmul($num, $weight, 2);
  341. $totalWeight = bcadd($totalWeight, $currentWeight, 2);
  342. $totalNum = bcadd($totalNum, $num);
  343. if ($product['limitBuy'] > 0) {
  344. $product['productId'] = $productId;
  345. \bizHd\product\classes\ProductClass::handleLimitBuy($product, $hdCustomId, floatval($num));
  346. }
  347. }
  348. $post['product'] = $productList;
  349. $post['reachDiscountPrice'] = $totalReachDiscount;
  350. //不能前端传运费过来,只能通过跑腿接口计算出来
  351. unset($post['sendCost']);
  352. $mapSet = ShopClass::hasIntraCity($this->shop);
  353. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  354. if (isset($post['sendType']) && $post['sendType'] == 2 && $openIntraCity != 0) {
  355. if ($openIntraCity == 2) {
  356. util::fail('不能使用跑腿');
  357. }
  358. $cargoName = '花材'; // 商品名称
  359. $cargo = [
  360. 'cargo_name' => $cargoName, // 商品名称
  361. 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  362. 'cargo_price' => intval($modifyPrice * 100), // 单位:分 -- 把元转换为分
  363. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  364. 'cargo_num' => $totalNum
  365. ];
  366. $customName = $custom->name;
  367. $customMobile = $custom->mobile;
  368. if (empty($post['long']) || empty($post['lat'])) {
  369. util::fail('位置错误');
  370. }
  371. // $originalLng = doubleval($post['long']);
  372. // $originalLat = doubleval($post['lat']);
  373. // $city = $post['city'] ?? '';
  374. // $dist = $post['dist'] ?? '';
  375. // $address = $post['address'] ?? '';
  376. // $showAddress = $post['showAddress'] ?? '';
  377. // $userAddress = $city . $dist . $address . "({$showAddress})";
  378. // $main = $this->main;
  379. $shop = $this->shop;
  380. $shopLat = $shop->lat ?? '';
  381. $shopLong = $shop->long ?? '';
  382. if (empty($shopLat) || empty($shopLong)) {
  383. util::fail('商家门店地址定位未设置,编号263');
  384. }
  385. // $wxStoreId = $main->wxStoreId ?? 0;
  386. // if (empty($wxStoreId)) {
  387. // util::fail('商家还没有开通跑腿功能');
  388. // }
  389. // $orderData = [
  390. // 'wx_store_id' => $wxStoreId,
  391. // 'user_name' => $customName,
  392. // 'user_phone' => $customMobile,
  393. // 'user_lng' => $originalLng,
  394. // 'user_lat' => $originalLat,
  395. // 'user_address' => $userAddress,
  396. // 'cargo' => $cargo,
  397. // ];
  398. // //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  399. // $result = IntraCityExpress::preAddOrder($orderData);
  400. // $errCode = $result['errcode'] ?? 1;
  401. // if ($errCode != 0) {
  402. // $errMsg = $result['errmsg'] ?? '';
  403. // util::fail('获取运费错误:' . $errMsg);
  404. // }
  405. // $fee = $result['est_fee'] ?? 0;
  406. // $distance = $result['distance'] ?? 0;
  407. // $sendCost = bcdiv($fee, 100, 2);
  408. $distance = 0;
  409. $sendCost = 0;
  410. //生成随机订单号,不要跟原来的混起来,跑腿-销售单-
  411. $prefix = 'PT-XSD-' . $this->mainId . '-';
  412. $orderSn = $prefix . round(microtime(true) * 1000);
  413. $ghsInfo = ['mainId' => $this->mainId, 'shopId' => $this->shopId];
  414. // 这儿要调用跑腿接口计算运费和距离
  415. try {
  416. if (empty($post['deliveryPlatform'])) {
  417. util::fail('请选择跑腿');
  418. }
  419. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  420. 'productList' => $productList,
  421. 'deliveryPlatform' => $post['deliveryPlatform'],
  422. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  423. 'ghsInfo' => $ghsInfo,
  424. 'custom' => $this->user, // $custom 数据有问题,要是 user
  425. 'order' => [
  426. 'orderSn' => $orderSn,
  427. 'goodsType' => 1, //商品类型:0花束 1花材
  428. 'itemTotalAmount' => $modifyPrice,
  429. 'remark' => $post['remark'] ?? '',
  430. ],
  431. 'mainId' => $this->mainId,
  432. 'productCount' => $totalNum,
  433. ]);
  434. $sendCost = $quoteResult['sendCost'];
  435. $distance = $quoteResult['sendDistance'];
  436. } catch (\Exception $e) {
  437. util::fail($e->getMessage());
  438. }
  439. $post['sendCost'] = $sendCost;
  440. $post['sendDistance'] = $distance;
  441. //noticeUtil::push("零售订单(花材),获取运费:{$sendCost} 重量:{$totalWeight} 距离:{$distance}m 姓名:{$customName} 手机号 {$customMobile} 金额:{$modifyPrice} 数量:{$totalNum}", '15280215347');
  442. $modifyPrice = bcadd($modifyPrice, $sendCost, 2);
  443. }
  444. //红包使用,多有处,关键词 use_hb_action
  445. $hbId = $post['hbId'] ?? 0;
  446. $hb = null;
  447. if ($hbId > 0) { // 不使用 $hbId =! 0,因为要用负数来表示红包已取消
  448. $hb = HbClass::getById($hbId, true);
  449. if (!empty($hb)) {
  450. if ($hb->customId != $hdCustomId) {
  451. util::fail('不是你的红包');
  452. }
  453. if ($hb->amount != $post['hbAmount']) {
  454. util::fail('红包金额不相等'); //红包数据可能被串改
  455. }
  456. if ($hb->status == 1) {
  457. util::fail('红包已使用');
  458. }
  459. if ($hb->status == -1) {
  460. util::fail('红包已作废');
  461. }
  462. if ($hb->endTime < time()) {
  463. $hb->status = -1;
  464. $hb->save();
  465. util::fail('红包已失效');
  466. }
  467. if ($hb->beginTime > time()) {
  468. util::fail('红包可使用期未到');
  469. }
  470. // 按适用范围计算适用商品合计是否达到最低消费
  471. HbScopeClass::assertMinConsume($hb, $productList ?? [], $modifyPrice);
  472. if ($this->shop->rechargeWeal == 3) {
  473. if (bccomp($custom->balance, $modifyPrice) == -1) {
  474. //不要限制提交
  475. //util::fail('此红包非余额支付不可用(您的余额不足)');
  476. }
  477. }
  478. $modifyPrice = bcsub($modifyPrice, $hb->amount, 2);//扣减红包
  479. } else {
  480. Yii::error('没有找到红包,hbId', $hbId . ' ' . __METHOD__);
  481. util::fail('红包无效');
  482. }
  483. }
  484. $post['bigNum'] = $totalNum;
  485. $post['modifyPrice'] = $modifyPrice;
  486. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  487. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  488. if (!empty($hb)) {
  489. $hb->status = 1;
  490. $hb->orderId = $return->id;
  491. $hb->save();
  492. }
  493. if (isset($return->shopId)) {
  494. if ($return->shopId == 7610) {
  495. if ($return->actPrice < 200) {
  496. if ($return->sendType == 0) {
  497. util::fail('满200元支持送货上门');
  498. }
  499. }
  500. }
  501. }
  502. if ($return->sendType == 2) {
  503. $ext = ShopExtClass::getByCondition(['shopId' => $return->shopId], true, null, 'id,shopId,thirdSend');
  504. if ($ext->thirdSend == 1) {
  505. util::fail('本店暂不能使用跑腿呢');
  506. }
  507. }
  508. $transaction->commit();
  509. $transactionFinished = true;
  510. \bizHd\product\classes\ProductClass::clearLimitBuyRollbackSnapshot();
  511. $orderSn = $return->orderSn ?? '';
  512. $orderPrice = $return->orderPrice ?? 0;
  513. $id = $return->id ?? 0;
  514. $getPayType = dict::getDict('getPayType');
  515. util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id, 'getPayType' => $getPayType]);
  516. } catch (\Exception $e) {
  517. $transaction->rollBack();
  518. \bizHd\product\classes\ProductClass::rollbackLimitBuySnapshot();
  519. $transactionFinished = true;
  520. Yii::error("失败原因:" . $e->getMessage());
  521. util::fail('下单失败');
  522. }
  523. }
  524. //商城下单操作 ssh 2019.12.3
  525. public function actionCreateOrder()
  526. {
  527. $post = Yii::$app->request->post();
  528. //避免重复提交
  529. $userId = $this->userId;
  530. util::checkRepeatCommit($userId, 3);
  531. $shop = $this->shop;
  532. $openShop = \bizHd\shop\classes\ShopClass::getOpenShop($shop);
  533. if ($openShop == 0) {
  534. util::fail('已休店');
  535. }
  536. $goodsId = $post['goodsId'] ?? 0;
  537. $specGoodsId = (int)($post['specGoodsId'] ?? 0);
  538. $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
  539. $sendType = $post['sendType'] ?? dict::getDict('sendType', 'thirdSend');
  540. if (empty($goodsId)) {
  541. util::fail('请选择商品');
  542. }
  543. $mainId = $this->mainId;
  544. $goodsInfo = GoodsClass::getById($goodsId, true);
  545. if (empty($goodsInfo)) {
  546. util::fail('没有找到商品');
  547. }
  548. if ($goodsInfo->mainId != $mainId) {
  549. util::fail('不是你的商品');
  550. }
  551. if ($specGoodsId > 0) {
  552. $specGoods = GoodsClass::getById($specGoodsId, true);
  553. if (empty($specGoods) || $specGoods->mainId != $mainId || $specGoods->masterId != $goodsId || $specGoods->delStatus != 0 || $specGoods->status != 1) {
  554. util::fail('规格不可用');
  555. }
  556. $goodsInfo = $specGoods;
  557. } elseif ((int)($goodsInfo->masterId ?? 0) === 0) {
  558. $hasSpecs = GoodsClass::getByCondition(['masterId'=>$goodsId, 'delStatus'=>0], true);
  559. if (!empty($hasSpecs)) util::fail('请选择规格');
  560. }
  561. $stock = $goodsInfo->stock ?? 0;
  562. if ($stock <= 0) {
  563. util::fail('库存不足');
  564. }
  565. $saleGoodsId = $specGoodsId > 0 ? $specGoodsId : $goodsId;
  566. $activityType = strval($post['activityType'] ?? '');
  567. //事务处理
  568. $connection = Yii::$app->db;
  569. $transaction = $connection->beginTransaction();
  570. $transactionFinished = false;
  571. register_shutdown_function(function () use (&$transactionFinished, $transaction) {
  572. if ($transactionFinished) {
  573. return;
  574. }
  575. HomePageModuleClass::rollbackSeckillReservationSnapshot();
  576. if ($transaction->isActive) {
  577. $transaction->rollBack();
  578. }
  579. });
  580. try {
  581. $custom = $this->custom;
  582. if (empty($custom)) {
  583. util::fail('个人信息缺失');
  584. }
  585. $customId = $custom->id ?? 0;
  586. $hd = $this->hd;
  587. $post['customId'] = $customId;
  588. $customName = $custom->name ?? '';
  589. $post['customName'] = $customName;
  590. $post['customNamePy'] = stringUtil::py($customName);
  591. $post['hdId'] = $hd->id ?? 0;
  592. $post['hdName'] = $hd->name ?? '';
  593. $user = $this->user;
  594. $post['bookName'] = $user->name ?? '';
  595. $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  596. $bookMobile = empty($bookMobile) && !empty($user->mobile) ? $user->mobile : $bookMobile;
  597. $post['bookMobile'] = $bookMobile;
  598. $post['payWay'] = 0;
  599. $shop = $this->shop;
  600. // 秒杀商品:不信任前端传的价格,独立回查秒杀配置核实活动状态/库存/限购后再核价
  601. $seckillRow = null;
  602. $seckillActivityGoodsId = 0;
  603. if ($activityType === 'seckill') {
  604. $seckillRow = HomePageModuleClass::getSeckillActiveRow($mainId, intval($this->shopId), $saleGoodsId);
  605. if (empty($seckillRow)) {
  606. util::fail('秒杀活动已结束或商品已下架,请重新选择');
  607. }
  608. $seckillActivityGoodsId = intval($seckillRow['id'] ?? ($seckillRow['activityGoodsId'] ?? 0));
  609. if ($seckillActivityGoodsId <= 0) {
  610. util::fail('秒杀商品版本无效,请重新选择');
  611. }
  612. $seckillStock = floatval($seckillRow['stock'] ?? 0);
  613. $soldCount = HomePageModuleClass::getSeckillSoldCount($mainId, $seckillActivityGoodsId);
  614. if (bcadd($soldCount, $goodsNum, 2) > $seckillStock) {
  615. util::fail('秒杀库存不足,请重新选择');
  616. }
  617. $seckillLimit = floatval($seckillRow['limit'] ?? 0);
  618. if ($seckillLimit > 0) {
  619. $boughtCount = HomePageModuleClass::getSeckillCustomBoughtCount($mainId, $seckillActivityGoodsId, $customId);
  620. if (bcadd($boughtCount, $goodsNum, 2) > $seckillLimit) {
  621. util::fail("秒杀商品每人限购{$seckillLimit}件,已超出可购买数量");
  622. }
  623. }
  624. }
  625. if ($seckillRow) {
  626. $goodsInfo->priceType = 1;
  627. $unitPrice = floatval($seckillRow['price'] ?? 0);
  628. if ($unitPrice <= 0) {
  629. util::fail('秒杀价格异常,不能下单');
  630. }
  631. // 通过校验后立即预占名额,失败/异常时随事务一起回滚(见 register_shutdown_function)
  632. HomePageModuleClass::reserveSeckillPurchase($mainId, $seckillActivityGoodsId, $customId, $goodsNum);
  633. } else {
  634. $params = [];
  635. $goodsData = $goodsInfo->attributes;
  636. $ret = \bizHd\goods\classes\GoodsClass::getFinalPrice($goodsData, $shop, $custom, $params);
  637. $goodsInfo->priceType = $ret['priceType'] ?? 0;
  638. if ($goodsInfo->priceType == 0) {
  639. util::fail('没有价格,不能下单哈');
  640. }
  641. $unitPrice = $ret['price'] ?? 0;
  642. if ($unitPrice <= 0) {
  643. util::fail('没有价格,不能下单呢');
  644. }
  645. }
  646. //计算总金额
  647. $goodsPrice = $unitPrice * $goodsNum;
  648. //计算运费
  649. $sendDistance = 0;
  650. $sendCost = 0;
  651. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  652. $receiveUserName = $post['receiveUserName'] ?? '';
  653. if (empty($receiveUserName)) {
  654. util::fail('请填写收花人名字');
  655. }
  656. $receiveMobile = $post['receiveMobile'] ?? '';
  657. if (empty($receiveMobile)) {
  658. util::fail('请填写收花人手机号');
  659. }
  660. if (!stringUtil::isMobile($receiveMobile)) {
  661. util::fail('收花人手机号错误');
  662. }
  663. }
  664. $mapSet = ShopClass::hasIntraCity($shop);
  665. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  666. if ($sendType == dict::getDict('sendType', 'thirdSend') && $openIntraCity != 0) {
  667. // if (dict::getDict('hasMap') == 0) {
  668. // util::fail('不能使用跑腿,请选其它方式');
  669. // }
  670. // $lat = $post['lat'] ?? '';
  671. // $lng = $post['long'] ?? '';
  672. // if ((empty($lat) || empty($lng))) { // 当 hasMap 为1时,经纬数据是必要的
  673. // util::fail('请填写正确地址');
  674. // }
  675. // $address = $post['address'] ?? '';
  676. // $floor = $post['floor'] ?? '';
  677. // $fullAddress = $address . $floor;
  678. // $post['fullAddress'] = $fullAddress;
  679. // $shopLat = $shop->lat ?? '';
  680. // $shopLong = $shop->long ?? '';
  681. // if (empty($shopLat) || empty($shopLong)) {
  682. // util::fail('商家门店地址定位未设置,编号8966');
  683. // }
  684. // $weight = $goodsInfo->weight ?? 0;
  685. // if ($weight <= 0) {
  686. // util::fail('商品没有重量');
  687. // }
  688. // $totalWeight = bcmul($weight, $goodsNum, 2);
  689. // $cargoName = '鲜花'; // 商品名称
  690. // $cargo = [
  691. // 'cargo_name' => $cargoName, // 商品名称
  692. // 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  693. // 'cargo_price' => intval($goodsPrice * 100), // 单位:分 -- 把元转换为分
  694. // 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  695. // 'cargo_num' => $goodsNum
  696. // ];
  697. // $customName = $custom->name;
  698. // $customMobile = $custom->mobile;
  699. // if (empty($post['long']) || empty($post['lat'])) {
  700. // util::fail('位置错误');
  701. // }
  702. // $originalLng = doubleval($post['long']);
  703. // $originalLat = doubleval($post['lat']);
  704. // $city = $post['city'] ?? '';
  705. // $dist = $post['dist'] ?? '';
  706. // $address = $post['address'] ?? '';
  707. // $showAddress = $post['showAddress'] ?? '';
  708. // $userAddress = $city . $dist . $address . "({$showAddress})";
  709. // $main = $this->main;
  710. // $shopLat = $shop->lat ?? '';
  711. // $shopLong = $shop->long ?? '';
  712. // if (empty($shopLat) || empty($shopLong)) {
  713. // util::fail('商家门店地址定位未设置,编号6880');
  714. // }
  715. // $wxStoreId = $main->wxStoreId ?? 0;
  716. // if (empty($wxStoreId)) {
  717. // util::fail('商家还没有开通跑腿功能');
  718. // }
  719. // $orderData = [
  720. // 'wx_store_id' => $wxStoreId,
  721. // 'user_name' => $customName,
  722. // 'user_phone' => $customMobile,
  723. // 'user_lng' => $originalLng,
  724. // 'user_lat' => $originalLat,
  725. // 'user_address' => $userAddress,
  726. // 'cargo' => $cargo,
  727. // ];
  728. // //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  729. // $result = IntraCityExpress::preAddOrder($orderData);
  730. // $errCode = $result['errcode'] ?? 1;
  731. // if ($errCode != 0) {
  732. // $errMsg = $result['errmsg'] ?? '';
  733. // util::fail('获取运费错误:' . $errMsg);
  734. // }
  735. // $fee = $result['est_fee'] ?? 0;
  736. // $sendDistance = $result['distance'] ?? 0;
  737. // $sendCost = bcdiv($fee, 100, 2);
  738. // //免运费的不收运费
  739. // if ($goodsInfo->freightType == 1) {
  740. // $sendCost = 0;
  741. // }
  742. // noticeUtil::push("零售订单!获取运费:{$sendCost} 重量:{$totalWeight} 距离:{$sendDistance} 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$goodsPrice} 数量:{$goodsNum}", '15280215347');
  743. if ($openIntraCity == 2) {
  744. util::fail('不能使用跑腿');
  745. }
  746. $cutomInfo = [
  747. 'name' => $post['receiveUserName'],
  748. 'mobile' => $post['receiveMobile'],
  749. 'fullAddress' => $post['address'],
  750. 'floor' => $post['floor'],
  751. 'dist' => $post[''] ?? '',
  752. 'lat' => $post['lat'],
  753. 'long' => $post['long'],
  754. 'address' => $post['address'],
  755. 'city' => $post['city'],
  756. ];
  757. $cutomInfo = (object)$cutomInfo;
  758. // 生成随机花束订单号
  759. $prefix = 'KD_CS-' . $this->mainId . '-';
  760. $orderSn = $prefix . round(microtime(true) * 1000);
  761. // 使用 DeliveryQuoteUtil 获取配送报价
  762. try {
  763. if ($goodsInfo->weight > 5) {
  764. $goodsInfo->weight = 5;
  765. }
  766. if (empty($post['deliveryPlatform'])) {
  767. util::fail('请选择跑腿');
  768. }
  769. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  770. 'productList' => [['bigNum' => $goodsNum, 'weight' => $goodsInfo->weight]],
  771. 'deliveryPlatform' => $post['deliveryPlatform'],
  772. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  773. 'ghsInfo' => ['mainId' => $mainId, 'shopId' => $this->shopId],
  774. 'custom' => $cutomInfo,
  775. 'order' => [
  776. 'orderSn' => $orderSn,
  777. 'goodsType' => 0, //商品类型:0花束 1花材
  778. 'itemTotalAmount' => $goodsPrice,
  779. 'remark' => $post['remark'] ?? '',
  780. 'freightType' => $goodsInfo->freightType,
  781. ],
  782. 'mainId' => $this->mainId,
  783. 'productCount' => $goodsNum,
  784. ]);
  785. $sendCost = $quoteResult['sendCost'];
  786. $sendDistance = $quoteResult['sendDistance'];
  787. noticeUtil::push("零售订单(花束),获取运费:{$sendCost} 重量:{$goodsInfo->weight} 距离:{$sendDistance}m 姓名:{$customName} 金额:{$goodsPrice} 数量:{$goodsNum}");
  788. } catch (\Exception $e) {
  789. util::fail($e->getMessage());
  790. }
  791. }
  792. $post['sendDistance'] = $sendDistance;
  793. $post['sendCost'] = $sendCost;
  794. $post['sjId'] = $this->sjId;
  795. $post['shopId'] = $this->shopId;
  796. $post['mainId'] = $mainId;
  797. $post['userId'] = $this->userId;
  798. if ($goodsInfo->priceType == 0) {
  799. util::fail('没有价格,不能下单');
  800. }
  801. $modifyPrice = stringUtil::calcAdd($sendCost, $goodsPrice);
  802. //非门店订单
  803. $post['store'] = 0;
  804. //红包使用,多有处,关键词 use_hb_action
  805. $hbId = $post['hbId'] ?? 0;
  806. $hb = null;
  807. if ($hbId > 0) { // 不使用 $hbId =! 0,因为要用负数来表示红包已取消
  808. $hb = HbClass::getById($hbId, true);
  809. if (!empty($hb)) {
  810. if ($hb->customId != $customId) {
  811. util::fail('不是你的红包');
  812. }
  813. if ($hb->amount != $post['hbAmount']) {
  814. util::fail('红包金额不相等'); //红包数据可能被串改
  815. }
  816. if ($hb->status == 1) {
  817. util::fail('红包已使用');
  818. }
  819. if ($hb->status == -1) {
  820. util::fail('红包已作废');
  821. }
  822. if ($hb->endTime < time()) {
  823. $hb->status = -1;
  824. $hb->save();
  825. util::fail('红包已失效');
  826. }
  827. if ($hb->beginTime > time()) {
  828. util::fail('红包可使用期未到');
  829. }
  830. // 单花束下单:按适用范围校验最低消费
  831. $hbGoods = [[
  832. 'productId' => $goodsInfo->id ?? 0,
  833. 'goodsId' => $goodsInfo->id ?? 0,
  834. 'unitPrice' => $goodsPrice ?? 0,
  835. 'num' => $goodsNum ?? 1,
  836. 'linePrice' => $goodsPrice ?? 0,
  837. ]];
  838. HbScopeClass::assertMinConsume($hb, $hbGoods, $modifyPrice);
  839. if ($this->shop->rechargeWeal == 3) {
  840. if ($custom->balance < $modifyPrice) {
  841. util::fail('此红包非余额支付不可用(您的余额不足)');
  842. }
  843. }
  844. $modifyPrice = bcsub($modifyPrice, $hb->amount, 2);//扣减红包
  845. } else {
  846. Yii::error('没有找到红包,hbId', $hbId . ' ' . __METHOD__);
  847. util::fail('红包无效');
  848. }
  849. }
  850. $post['modifyPrice'] = $modifyPrice;
  851. //非自取订单考虑配送时间
  852. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  853. $sendType = $post['sendType'] ?? 0;
  854. if ($sendType != 1) {
  855. if (empty($post['reachPeriod'])) {
  856. util::fail('请选择配送时间哈');
  857. }
  858. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  859. }
  860. $now = time();
  861. $expireTime = $now + 1800;//订单30分钟后过期
  862. $post['deadline'] = $expireTime;
  863. $orderSn = orderSn::getOrderSn();
  864. $post['orderSn'] = $orderSn;
  865. $post['fromType'] = dict::getDict('fromType', 'mall');
  866. $post['cash'] = 0;
  867. $post['mainId'] = $mainId;
  868. $post['needPrint'] = dict::getDict('needPrint', 'need');
  869. $hasPay = 0;
  870. $product = [['productId' => $saleGoodsId, 'unitType' => 0, 'property' => 0, 'unitPrice' => $unitPrice, 'num' => $goodsNum, 'seckillGoodsId' => $seckillActivityGoodsId]];
  871. $post['product'] = $product;
  872. $post['hasSeckill'] = $seckillRow ? 1 : 0;
  873. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  874. //红包保存订单id
  875. if (!empty($hb)) {
  876. $hb->status = 1;
  877. $hb->orderId = $return->id;
  878. $hb->save();
  879. }
  880. $orderId = $return->id;
  881. $orderSn = $return->orderSn;
  882. $actPrice = $return->actPrice ?? 0;
  883. $transaction->commit();
  884. $transactionFinished = true;
  885. HomePageModuleClass::clearSeckillReservationSnapshot();
  886. util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => 0, 'id' => $orderId]);
  887. } catch (Exception $e) {
  888. $transaction->rollBack();
  889. HomePageModuleClass::rollbackSeckillReservationSnapshot();
  890. $transactionFinished = true;
  891. Yii::info("失败原因:" . $e->getMessage());
  892. util::fail('下单失败');
  893. }
  894. }
  895. /**
  896. * 花束+花材合并结算下单
  897. * 复用 OrderService::createHdOrder,不改动 buy-item / create-order
  898. */
  899. public function actionCreateMixOrder()
  900. {
  901. $post = Yii::$app->request->post();
  902. $post['sjId'] = $this->sjId;
  903. $post['shopId'] = $this->shopId;
  904. $post['payWay'] = 0;
  905. $post['mainId'] = $this->mainId ?? 0;
  906. $post['userId'] = $this->userId ?? 0;
  907. $userId = $this->userId;
  908. util::checkRepeatCommit($userId, 3);
  909. $mainId = $this->mainId;
  910. $shop = $this->shop;
  911. $openShop = \bizHd\shop\classes\ShopClass::getOpenShop($shop);
  912. if ($openShop == 0) {
  913. util::fail('已休店');
  914. }
  915. $hdId = $post['hdId'] ?? 0;
  916. $hd = HdClass::getById($hdId, true);
  917. if (empty($hd)) {
  918. util::fail('没有找到花店');
  919. }
  920. if ($hd->shopId != $this->shopId) {
  921. util::fail('不是你的花店');
  922. }
  923. $post['hdName'] = $hd->name ?? '';
  924. // 合并结算沿用花材购物车的客户身份(花店客户)
  925. $hdCustomId = $hd->customId ?? 0;
  926. $custom = CustomClass::getById($hdCustomId, true);
  927. if (empty($custom)) {
  928. util::fail('没有找到客户');
  929. }
  930. $customName = $custom->name;
  931. $post['customId'] = $hdCustomId;
  932. $post['customName'] = $customName;
  933. $post['customNamePy'] = stringUtil::py($customName);
  934. $productJson = $post['product'];
  935. if (empty($productJson)) {
  936. util::fail('请选择商品');
  937. }
  938. $productList = json_decode($productJson, true);
  939. if (empty($productList) || !is_array($productList)) {
  940. util::fail('请选择商品');
  941. }
  942. $itemRows = []; // 所有花材
  943. $goodsRows = []; // 所有花束
  944. foreach ($productList as $idx => $row) {
  945. $property = intval($row['property'] ?? -1);
  946. if ($property === 1) {
  947. $itemRows[$idx] = $row;
  948. } elseif ($property === 0) {
  949. $goodsRows[$idx] = $row;
  950. } else {
  951. util::fail('商品类型错误');
  952. }
  953. }
  954. if (empty($itemRows) && empty($goodsRows)) {
  955. util::fail('请选择商品');
  956. }
  957. // ---- 花材校验与定价 ----
  958. $productInfoList = [];
  959. if (!empty($itemRows)) {
  960. $ids = array_unique(array_filter(array_map(function ($r) {
  961. return intval($r['productId'] ?? 0);
  962. }, $itemRows)));
  963. $productInfoList = ProductClass::getByIds($ids, null, 'id');
  964. if (empty($productInfoList)) {
  965. util::fail('花材不存在');
  966. }
  967. $presellData = [];
  968. $nowTime = strtotime(date("Y-m-d"));
  969. foreach ($productInfoList as $currentInfo) {
  970. if (!isset($currentInfo['mainId']) || $currentInfo['mainId'] != $this->mainId) {
  971. util::fail('只能选一家的商品,请清空重新选呢');
  972. }
  973. $presell = $currentInfo['presell'] ?? 0;
  974. $presellData[] = $presell;
  975. if ($presell == 1) {
  976. if (empty($post['reachDate'])) {
  977. util::fail('请选择配送或取货日期');
  978. }
  979. $sendTimeWant = $post['reachDate'];
  980. if (strtotime($sendTimeWant) < $nowTime) {
  981. util::fail('不能选择过去时间');
  982. }
  983. $hasDateStr = $currentInfo['presellDate'] ?? [];
  984. $hasDate = explode(',', trim($hasDateStr));
  985. if (empty($hasDate)) {
  986. util::fail('预售日期有问题,请提醒门店');
  987. }
  988. if (!in_array(strtotime($sendTimeWant), $hasDate)) {
  989. util::fail("有预售花材在{$sendTimeWant}没到货");
  990. }
  991. $post['presell'] = 1;
  992. }
  993. }
  994. if (count($productInfoList) != count($ids)) {
  995. util::fail('存在无效花材');
  996. }
  997. $presellData = array_unique($presellData);
  998. if (count($presellData) > 1) {
  999. util::fail('预售和非预售花材不能一起下单');
  1000. }
  1001. }
  1002. $connection = Yii::$app->db;
  1003. $transaction = $connection->beginTransaction();
  1004. $transactionFinished = false;
  1005. register_shutdown_function(function () use (&$transactionFinished, $transaction) {
  1006. if ($transactionFinished) {
  1007. return;
  1008. }
  1009. \bizHd\product\classes\ProductClass::rollbackLimitBuySnapshot();
  1010. HomePageModuleClass::rollbackSeckillReservationSnapshot();
  1011. if ($transaction->isActive) {
  1012. $transaction->rollBack();
  1013. }
  1014. });
  1015. try {
  1016. $orderValidTime = !getenv('ORDER_VALID_TIME') ? 600 : getenv('ORDER_VALID_TIME'); // TODO 找少华确认 -- 测试环境是 600
  1017. $post['deadline'] = time() + $orderValidTime;
  1018. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  1019. $post['needPrint'] = dict::getDict('needPrint', 'need');
  1020. $post['fromType'] = dict::getDict('fromType', 'mall');
  1021. $post['store'] = 0;
  1022. $user = $this->user;
  1023. $post['bookMobile'] = $user->mobile ?? '';
  1024. $post['bookName'] = $user->name ?? '';
  1025. $hasPay = 0;
  1026. $modifyPrice = 0;
  1027. $totalWeight = 0;
  1028. $totalNum = 0;
  1029. $itemBigNum = 0;
  1030. $totalReachDiscount = 0;
  1031. $resolvedProduct = [];
  1032. $hasSeckillGoods = false;
  1033. $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
  1034. $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
  1035. $post['orderType'] = 0;
  1036. foreach ($productList as $eleKey => $element) {
  1037. $property = $element['property']; // 1: 花材, 0: 花束
  1038. if ($property === 1) { // 花材
  1039. $level = 0;
  1040. $productId = $element['productId'];
  1041. $product = $productInfoList[$productId] ?? null;
  1042. if (empty($product)) {
  1043. util::fail('有花材信息没有找到');
  1044. }
  1045. $num = $element['num'] ?? 0;
  1046. $limitKey = \bizHd\product\classes\ProductClass::LIMIT_BUY_KEY . $productId;
  1047. $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $hdCustomId]);
  1048. $hasBuyNum = $num + ($hasBuyNum == null ? 0 : $hasBuyNum);
  1049. $price = \bizGhs\product\classes\ProductClass::getFinalPrice($product, $level, $priceMap, $addPriceMap, 0, $num, $hasBuyNum);
  1050. $reachNum = $product['reachNum'] ?? 0;
  1051. $reachNumDiscount = $product['reachNumDiscount'] ?? 0;
  1052. if ($reachNum > 0 && $num >= $reachNum && $reachNumDiscount > 0) {
  1053. $currentReachDiscount = bcmul($reachNumDiscount, $num, 2);
  1054. $totalReachDiscount = bcadd($totalReachDiscount, $currentReachDiscount, 2);
  1055. }
  1056. $currentTotal = bcmul($price, $num, 2);
  1057. $modifyPrice = bcadd($modifyPrice, $currentTotal, 2);
  1058. $weight = $product['weight'] ?? 0;
  1059. $currentWeight = bcmul($num, $weight, 2);
  1060. $totalWeight = bcadd($totalWeight, $currentWeight, 2);
  1061. $totalNum = bcadd($totalNum, $num);
  1062. $itemBigNum = bcadd($itemBigNum, $num);
  1063. if (($product['limitBuy'] ?? 0) > 0) {
  1064. $product['productId'] = $productId;
  1065. \bizHd\product\classes\ProductClass::handleLimitBuy($product, $hdCustomId, floatval($num));
  1066. }
  1067. $resolvedProduct[] = [
  1068. 'productId' => $productId,
  1069. 'num' => $num,
  1070. 'itemId' => $element['itemId'] ?? 0,
  1071. 'unitType' => $element['unitType'] ?? 0,
  1072. 'property' => 1,
  1073. 'unitPrice' => $price,
  1074. ];
  1075. } else if ($property === 0) { // 花束
  1076. $goodsId = $element['goodsId']; // 主商品ID
  1077. $specGoodsId = $element['specGoodsId']; // 规格ID
  1078. $saleGoodsId = $element['productId']; // 记录用于销售的商品ID,通常为具体的规格或产品ID
  1079. $goodsNum = isset($element['num']) && $element['num'] > 0 ? $element['num'] : 1;
  1080. if ($goodsId <= 0 && $saleGoodsId > 0) {
  1081. $probe = GoodsClass::getById($saleGoodsId, true);
  1082. if (!empty($probe)) {
  1083. $masterId = intval($probe->masterId);
  1084. if ($masterId > 0) {
  1085. $goodsId = $masterId;
  1086. $specGoodsId = $saleGoodsId;
  1087. } else {
  1088. $goodsId = $saleGoodsId;
  1089. }
  1090. }
  1091. }
  1092. if ($goodsId <= 0) {
  1093. util::fail('请选择花束商品');
  1094. }
  1095. $goodsInfo = GoodsClass::getById($goodsId, true);
  1096. if (empty($goodsInfo)) {
  1097. util::fail('没有找到花束商品');
  1098. }
  1099. if ($goodsInfo->mainId != $mainId) {
  1100. util::fail('不是你的商品');
  1101. }
  1102. if ($specGoodsId > 0) {
  1103. $specGoods = GoodsClass::getById($specGoodsId, true);
  1104. if (empty($specGoods) || $specGoods->mainId != $mainId || $specGoods->masterId != $goodsId || $specGoods->delStatus != 0 || $specGoods->status != 1) {
  1105. util::fail('规格不可用');
  1106. }
  1107. $goodsInfo = $specGoods;
  1108. $saleGoodsId = $specGoodsId;
  1109. } else {
  1110. if ((int)($goodsInfo->masterId ?? 0) === 0) {
  1111. $hasSpecs = GoodsClass::getByCondition(['masterId' => $goodsId, 'delStatus' => 0], true);
  1112. if (!empty($hasSpecs)) {
  1113. util::fail('请选择规格');
  1114. }
  1115. }
  1116. $saleGoodsId = $goodsId;
  1117. }
  1118. $stock = $goodsInfo->stock;
  1119. $stockSet = $goodsInfo->stockSet;
  1120. if ($stockSet == 1 && $stock <= 0) {
  1121. util::fail('花束库存不足');
  1122. }
  1123. // 秒杀商品:不信任前端传的价格,独立回查秒杀配置核实活动状态/库存/限购后再核价
  1124. $seckillRow = null;
  1125. $seckillActivityGoodsId = 0;
  1126. if (strval($element['activityType'] ?? '') === 'seckill') {
  1127. $seckillRow = HomePageModuleClass::getSeckillActiveRow($mainId, intval($this->shopId), $saleGoodsId);
  1128. if (empty($seckillRow)) {
  1129. util::fail('秒杀活动已结束或商品已下架,请重新选择');
  1130. }
  1131. $seckillActivityGoodsId = intval($seckillRow['id'] ?? ($seckillRow['activityGoodsId'] ?? 0));
  1132. if ($seckillActivityGoodsId <= 0) {
  1133. util::fail('秒杀商品版本无效,请重新选择');
  1134. }
  1135. $seckillStock = floatval($seckillRow['stock']);
  1136. $soldCount = HomePageModuleClass::getSeckillSoldCount($mainId, $seckillActivityGoodsId);
  1137. if (bcadd($soldCount, $goodsNum, 2) > $seckillStock) {
  1138. util::fail('秒杀库存不足,请重新选择');
  1139. }
  1140. $seckillLimit = floatval($seckillRow['limit'] ?? 0);
  1141. if ($seckillLimit > 0) {
  1142. $boughtCount = HomePageModuleClass::getSeckillCustomBoughtCount($mainId, $seckillActivityGoodsId, $hdCustomId); // TODO 同一个商品,如果缓存没有合理清除,就会一直限购
  1143. if (bcadd($boughtCount, $goodsNum, 2) > $seckillLimit) {
  1144. util::fail("秒杀商品每人限购{$seckillLimit}件,已超出可购买数量");
  1145. }
  1146. }
  1147. }
  1148. $goodsData = $goodsInfo->attributes;
  1149. if ($seckillRow) {
  1150. $unitPrice = floatval($seckillRow['price'] ?? 0);
  1151. if ($unitPrice <= 0) {
  1152. util::fail('秒杀价格异常,不能下单');
  1153. }
  1154. } else {
  1155. $ret = \bizHd\goods\classes\GoodsClass::getFinalPrice($goodsData, $shop, $custom, []);
  1156. $priceType = $ret['priceType'] ?? 0;
  1157. if ($priceType == 0) {
  1158. util::fail('花束没有价格,不能下单');
  1159. }
  1160. $unitPrice = $ret['price'] ?? 0;
  1161. if ($unitPrice <= 0) {
  1162. util::fail('花束没有价格,不能下单');
  1163. }
  1164. }
  1165. if ($seckillRow) {
  1166. // 通过校验后立即预占名额,失败/异常时随事务一起回滚(见 register_shutdown_function)
  1167. HomePageModuleClass::reserveSeckillPurchase($mainId, $seckillActivityGoodsId, $hdCustomId, $goodsNum);
  1168. $hasSeckillGoods = true;
  1169. }
  1170. $currentTotal = bcmul($unitPrice, $goodsNum, 2);
  1171. $modifyPrice = bcadd($modifyPrice, $currentTotal, 2);
  1172. $weight = $goodsInfo->weight ?? 0;
  1173. if ($weight > 5) {
  1174. $weight = 5;
  1175. }
  1176. $currentWeight = bcmul($weight, $goodsNum, 2);
  1177. $totalWeight = bcadd($totalWeight, $currentWeight, 2);
  1178. $totalNum = bcadd($totalNum, $goodsNum);
  1179. $resolvedProduct[] = [
  1180. 'productId' => $saleGoodsId,
  1181. 'unitType' => 0,
  1182. 'property' => 0,
  1183. // 花束是否包运费:供跑腿运费分支判断(1=包运费)
  1184. 'freightType' => (int)($goodsInfo->freightType ?? 0),
  1185. 'unitPrice' => $unitPrice,
  1186. 'num' => $goodsNum,
  1187. 'seckillGoodsId' => $seckillActivityGoodsId,
  1188. ];
  1189. } else {
  1190. util::fail('商品类型错误');
  1191. }
  1192. }
  1193. // 根据 $resolvedProduct 设置订单类型:1纯花束 2纯花材 3混合
  1194. $properties = array_unique(array_column($resolvedProduct, 'property'));
  1195. if (count($properties) === 1) {
  1196. $post['orderType'] = intval($properties[0]) === 0 ? 1 : 2;
  1197. } elseif (count($properties) > 1) {
  1198. $post['orderType'] = 3;
  1199. }
  1200. $post['product'] = $resolvedProduct;
  1201. $post['reachDiscountPrice'] = $totalReachDiscount;
  1202. $goodsOnlyPrice = $modifyPrice;
  1203. unset($post['sendCost'], $post['packCost'], $post['packingFee'], $post['unMeetSendCost']);
  1204. $sendType = intval($post['sendType'] ?? 0);
  1205. $customInfo = \bizHd\order\classes\PsMethodClass::buildCustomInfo($hd, $custom);
  1206. // 最低消费数量:花材扎数 + 花束份数(与结算页「还差 N 扎」同源)
  1207. $unMeetBigNum = $itemBigNum;
  1208. foreach ($resolvedProduct as $row) {
  1209. if ((int)($row['property'] ?? 1) === 0) {
  1210. $unMeetBigNum = bcadd($unMeetBigNum, $row['num'] ?? 0, 2);
  1211. }
  1212. }
  1213. $additionalCosts = \bizHd\order\classes\PsMethodClass::calcFeeForMallContext(
  1214. $this->shopId,
  1215. $this->mainId,
  1216. $sendType,
  1217. $goodsOnlyPrice,
  1218. $unMeetBigNum,
  1219. $hdCustomId,
  1220. $customInfo
  1221. );
  1222. $unMeetSendCost = $additionalCosts['sendCost'] ?? 0;
  1223. $packingFee = $additionalCosts['packCost'] ?? 0;
  1224. $mapSet = ShopClass::hasIntraCity($this->shop);
  1225. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  1226. $hasItem = !empty($itemRows);
  1227. // 含花材(含混合)按花材报价 goodsType=1;纯花束按 0
  1228. $quoteGoodsType = $hasItem ? 1 : 0;
  1229. // 跑腿 style=2:按包运费花束 / 不包运费花束 / 纯花材满减 + 跑腿或自定义(异常兜底)
  1230. if (isset($post['sendType']) && (int)$post['sendType'] === 2) {
  1231. if ((int)$openIntraCity === 2) {
  1232. util::fail('不能使用跑腿');
  1233. }
  1234. if (empty($post['long']) || empty($post['lat'])) {
  1235. util::fail('位置错误');
  1236. }
  1237. $shopLat = $shop->lat ?? '';
  1238. $shopLong = $shop->long ?? '';
  1239. if (empty($shopLat) || empty($shopLong)) {
  1240. util::fail('商家门店地址定位未设置,编号263');
  1241. }
  1242. $psConfig = PsMethodClass::getConfig($this->shopId, $this->mainId, 2);
  1243. if (empty($psConfig) || (int)($psConfig['status'] ?? 0) !== 1) {
  1244. util::fail('跑腿配送方式未启用');
  1245. }
  1246. $freightMode = PsMethodClass::resolveMixRunnerFreightMode($resolvedProduct);
  1247. $calcType = (int)($psConfig['calcType'] ?? 0);
  1248. $quoteCustom = (object)[
  1249. 'name' => $post['receiveUserName'] ?? '',
  1250. 'mobile' => $post['receiveMobile'] ?? '',
  1251. 'fullAddress' => $post['address'] ?? ($post['fullAddress'] ?? ''),
  1252. 'floor' => $post['floor'] ?? '',
  1253. 'dist' => $post['dist'] ?? '',
  1254. 'lat' => $post['lat'],
  1255. 'long' => $post['long'],
  1256. 'address' => $post['address'] ?? '',
  1257. 'city' => $post['city'] ?? '',
  1258. ];
  1259. $distanceRespond = mapUtil::calcShopDistanceByEleBike($quoteCustom, $shop, 0);
  1260. $distanceMeters = (float)($distanceRespond['distance'] ?? 0);
  1261. $distanceKm = (float)($distanceRespond['distanceKm'] ?? 0);
  1262. if ($distanceMeters <= 0 && $distanceKm <= 0) {
  1263. util::fail('算运费失败,请完善收货地址');
  1264. }
  1265. if ($distanceMeters <= 0 && $distanceKm > 0) {
  1266. $distanceMeters = $distanceKm * 1000;
  1267. }
  1268. $sendCost = 0;
  1269. $freightSource = '';
  1270. if ($freightMode === 'bouquetIncluded') {
  1271. // A:含包运费花束 → hsFreeKm / hsPerKmPrice
  1272. $sendCost = PsMethodClass::calcBouquetFreightByDistance($psConfig, $distanceMeters);
  1273. $freightSource = 'bouquetIncluded';
  1274. } elseif ($freightMode === 'flowerOnly'
  1275. && PsMethodClass::matchReduceRuleFree($psConfig, $distanceMeters, $itemBigNum, $goodsOnlyPrice)) {
  1276. // C:纯花材命中满减 → 免跑腿
  1277. $sendCost = 0;
  1278. $freightSource = 'reduceFree';
  1279. } else {
  1280. // B 或不免满减的 C:按 calcType 跑腿或自定义;跑腿异常最终自定义兜底
  1281. if ($calcType === 1) {
  1282. try {
  1283. $sendCost = PsMethodClass::calcCustomFreightByDistance($psConfig, $distanceKm > 0 ? $distanceKm : ($distanceMeters / 1000));
  1284. $freightSource = 'custom';
  1285. } catch (\Exception $e) {
  1286. util::fail($e->getMessage());
  1287. }
  1288. } else {
  1289. $runnerOk = false;
  1290. if ((int)$openIntraCity === 1 && !empty($post['deliveryPlatform'])) {
  1291. $prefix = 'PT-MIX-' . $this->mainId . '-';
  1292. $orderSn = $prefix . round(microtime(true) * 1000);
  1293. $ghsInfo = ['mainId' => $this->mainId, 'shopId' => $this->shopId];
  1294. try {
  1295. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  1296. 'productList' => $resolvedProduct,
  1297. 'deliveryPlatform' => $post['deliveryPlatform'],
  1298. 'deliveryBracketContent' => $post['deliveryBracketContent'] ?? '',
  1299. 'ghsInfo' => $ghsInfo,
  1300. 'custom' => $quoteCustom,
  1301. 'order' => [
  1302. 'orderSn' => $orderSn,
  1303. 'goodsType' => $quoteGoodsType,
  1304. 'itemTotalAmount' => $goodsOnlyPrice,
  1305. 'remark' => $post['remark'] ?? '',
  1306. ],
  1307. 'mainId' => $this->mainId,
  1308. 'productCount' => $totalNum,
  1309. 'shConfig' => $psConfig,
  1310. ]);
  1311. $sendCost = $quoteResult['sendCost'];
  1312. $distanceMeters = (float)($quoteResult['sendDistance'] ?? $distanceMeters);
  1313. $freightSource = 'platform';
  1314. $runnerOk = true;
  1315. } catch (\Exception $e) {
  1316. $runnerOk = false;
  1317. noticeUtil::push('商城混合单跑腿报价异常,改走自定义:' . $e->getMessage());
  1318. }
  1319. }
  1320. if (!$runnerOk) {
  1321. try {
  1322. $sendCost = PsMethodClass::calcCustomFreightByDistance(
  1323. $psConfig,
  1324. $distanceKm > 0 ? $distanceKm : ($distanceMeters / 1000)
  1325. );
  1326. $freightSource = 'customFallback';
  1327. } catch (\Exception $e) {
  1328. util::fail('跑腿计算异常且自定义计费不可用,请更换配送方式');
  1329. }
  1330. }
  1331. }
  1332. }
  1333. $post['sendCost'] = $sendCost;
  1334. $post['sendDistance'] = $distanceMeters;
  1335. $post['freightSource'] = $freightSource;
  1336. $modifyPrice = bcadd($modifyPrice, $sendCost, 2);
  1337. }
  1338. if ($unMeetSendCost > 0) {
  1339. $post['sendCost'] = bcadd($post['sendCost'] ?? 0, $unMeetSendCost, 2);
  1340. $modifyPrice = bcadd($modifyPrice, $unMeetSendCost, 2);
  1341. }
  1342. if ($packingFee > 0) {
  1343. $post['packingFee'] = $packingFee;
  1344. $modifyPrice = bcadd($modifyPrice, $packingFee, 2);
  1345. }
  1346. // 红包(归属花店客户,与 buy-item 一致)
  1347. $hbId = $post['hbId'] ?? 0;
  1348. $hb = null;
  1349. if ($hbId > 0) {
  1350. $hb = HbClass::getById($hbId, true);
  1351. if (!empty($hb)) {
  1352. if ($hb->customId != $hdCustomId) {
  1353. util::fail('不是你的红包');
  1354. }
  1355. if ($hb->amount != $post['hbAmount']) {
  1356. util::fail('红包金额不相等');
  1357. }
  1358. if ($hb->status == 1) {
  1359. util::fail('红包已使用');
  1360. }
  1361. if ($hb->status == -1) {
  1362. util::fail('红包已作废');
  1363. }
  1364. if ($hb->endTime < time()) {
  1365. $hb->status = -1;
  1366. $hb->save();
  1367. util::fail('红包已失效');
  1368. }
  1369. if ($hb->beginTime > time()) {
  1370. util::fail('红包可使用期未到');
  1371. }
  1372. // 混合结算:按适用范围用商品明细校验最低消费(不含运费包装费)
  1373. HbScopeClass::assertMinConsume($hb, $resolvedProduct ?? [], $goodsOnlyPrice ?? $modifyPrice);
  1374. $modifyPrice = bcsub($modifyPrice, $hb->amount, 2);
  1375. } else {
  1376. util::fail('红包无效');
  1377. }
  1378. }
  1379. $psMethodError = \bizHd\order\classes\PsMethodClass::checkLimit(
  1380. $this->shopId,
  1381. $this->mainId,
  1382. $sendType,
  1383. $goodsOnlyPrice,
  1384. $unMeetBigNum,
  1385. $packingFee,
  1386. $unMeetSendCost,
  1387. $hdCustomId,
  1388. $customInfo
  1389. );
  1390. if ($psMethodError !== '') {
  1391. util::fail($psMethodError);
  1392. }
  1393. // 商家配送(0)/跑腿(2)必填配送时间;到店自取(1)、物流(3)、快递(4)不强制(后两者由客服确认时效)
  1394. $sendType = intval($post['sendType'] ?? 0);
  1395. if (in_array($sendType, [0, 2], true)) {
  1396. if (empty($post['reachPeriod'])) {
  1397. util::fail('请选择配送时间哈');
  1398. }
  1399. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  1400. } elseif (!empty($post['reachPeriod'])) {
  1401. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  1402. }
  1403. $post['bigNum'] = $totalNum;
  1404. $post['modifyPrice'] = $modifyPrice;
  1405. $post['hasSeckill'] = $hasSeckillGoods ? 1 : 0;
  1406. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  1407. $orderSn = $return->orderSn ?? '';
  1408. if (!empty($orderSn) && (float)$unMeetSendCost > 0) {
  1409. $unMeetSendKey = 'hd_order_unmeet_send:' . $orderSn;
  1410. Yii::$app->redis->executeCommand('SETEX', [$unMeetSendKey, 864000, (string)$unMeetSendCost]);
  1411. }
  1412. if (!empty($hb)) {
  1413. $hb->status = 1;
  1414. $hb->orderId = $return->id;
  1415. $hb->save();
  1416. }
  1417. if ($return->sendType == 2) {
  1418. $ext = ShopExtClass::getByCondition(['shopId' => $return->shopId], true, null, 'id,shopId,thirdSend');
  1419. if (!empty($ext) && $ext->thirdSend == 1) {
  1420. util::fail('本店暂不能使用跑腿呢');
  1421. }
  1422. }
  1423. $transaction->commit();
  1424. $transactionFinished = true;
  1425. \bizHd\product\classes\ProductClass::clearLimitBuyRollbackSnapshot();
  1426. HomePageModuleClass::clearSeckillReservationSnapshot();
  1427. $orderSn = $return->orderSn ?? '';
  1428. $orderPrice = $return->orderPrice ?? ($return->actPrice ?? 0);
  1429. $id = $return->id ?? 0;
  1430. $getPayType = dict::getDict('getPayType');
  1431. util::success([
  1432. 'orderSn' => $orderSn,
  1433. 'totalPrice' => $orderPrice,
  1434. 'couponId' => 0,
  1435. 'id' => $id,
  1436. 'getPayType' => $getPayType,
  1437. ]);
  1438. } catch (\Exception $e) {
  1439. $transaction->rollBack();
  1440. \bizHd\product\classes\ProductClass::rollbackLimitBuySnapshot();
  1441. HomePageModuleClass::rollbackSeckillReservationSnapshot();
  1442. $transactionFinished = true;
  1443. Yii::error("合并下单失败:" . $e->getMessage());
  1444. util::fail('下单失败');
  1445. }
  1446. }
  1447. //下单要用到的相关信息 ssh 2019.12.6
  1448. public function actionOrderRelate()
  1449. {
  1450. $regionTree = RegionService::tree();
  1451. //门店名称
  1452. $shop = !empty($this->shop) ? $this->shop->attributes : [];
  1453. $sjName = $shop['merchantName'] ?? '';
  1454. $shopName = $shop['shopName'] ?? '';
  1455. $shop['showName'] = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1456. $avatar = $shop['avatar'] ?? '';
  1457. $smallAvatar = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  1458. $shop['smallAvatar'] = $smallAvatar;
  1459. $freight = ['first' => 5, 'add' => 2];
  1460. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1461. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  1462. util::success($out);
  1463. }
  1464. //余额支付 ssh 20250410
  1465. public function actionBalancePay()
  1466. {
  1467. $post = Yii::$app->request->post();
  1468. $orderSn = $post['orderSn'] ?? '';
  1469. //避免重复提交
  1470. util::checkRepeatCommit($orderSn, 5);
  1471. $connection = Yii::$app->db;
  1472. $transaction = $connection->beginTransaction();
  1473. try {
  1474. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  1475. if (empty($order)) {
  1476. util::fail('没有找到订单');
  1477. }
  1478. if ($order->shopId != $this->shopId) {
  1479. util::fail('不是你的订单');
  1480. }
  1481. //支付前验证订单有效性
  1482. OrderService::checkBeforePay($order);
  1483. $payWay = dict::getDict('payWay', 'balancePay');
  1484. \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
  1485. $transaction->commit();
  1486. //解决重复通知,重要
  1487. $cacheKey = 'mall_order_balance_pay_' . $orderSn;
  1488. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1489. if (empty($has)) {
  1490. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  1491. //打印小票和语音播报
  1492. $order = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  1493. if (!empty($order)) {
  1494. \bizHd\order\classes\OrderClass::onlinePrint($order);
  1495. //付款成功了,通知发跑腿功能,关键词 hd_pay_after_call_pt,多处要同步修改
  1496. HdDeliveryOrderClass::payAfter($order);
  1497. $shopId = $order->shopId ?? 0;
  1498. $shop = ShopClass::getById($shopId, true);
  1499. if (in_array($order->fromType, [1, 3])) {
  1500. //您有新的收入提醒
  1501. WxMessageClass::gatheringIncomeInform($shop, $order);
  1502. }
  1503. if ($order->fromType == 2) {
  1504. //来自商城的新订单微信通知
  1505. WxMessageClass::hdNewOrderInform($shop, $order);
  1506. }
  1507. }
  1508. }
  1509. util::complete('支付成功');
  1510. } catch (\Exception $e) {
  1511. $transaction->rollBack();
  1512. Yii::error("支付原因:" . $e->getMessage());
  1513. util::fail('支付失败');
  1514. }
  1515. }
  1516. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1517. public function actionWxPay()
  1518. {
  1519. ini_set('date.timezone', 'Asia/Shanghai');
  1520. $post = Yii::$app->request->post();
  1521. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  1522. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1523. $order = OrderService::getByOrderSn($orderSn);
  1524. $orderId = $order['id'];
  1525. //验证优惠券是否还有效
  1526. if (!empty($couponId)) {
  1527. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  1528. }
  1529. //支付前验证订单有效性
  1530. OrderService::checkBeforePay($order);
  1531. $name = !empty($order['orderName']) ? $order['orderName'] : '购买花材';
  1532. $shop = $this->shop;
  1533. if (empty($shop)) {
  1534. util::fail('没有找到门店信息');
  1535. }
  1536. if (isset($shop->shopName) && !empty($shop->shopName)) {
  1537. $name .= '(' . $shop->shopName . ')';
  1538. }
  1539. $totalFee = $order['mainPay'];
  1540. $openId = '';
  1541. if (!empty($post['miniOpenId'])) {
  1542. $openId = $post['miniOpenId'];
  1543. //noticeUtil::push('散客买花时,通过前端获取了openId:' . $openId, '15280215347');
  1544. }
  1545. if (empty($openId)) {
  1546. if (isset($this->user['miniOpenId']) && !empty($this->user['miniOpenId'])) {
  1547. $openId = $this->user['miniOpenId'];
  1548. //noticeUtil::push('散客买花时,通过数据库获取了openId:' . $openId, '15280215347');
  1549. }
  1550. }
  1551. if (empty($openId)) {
  1552. util::fail('没有找到openId');
  1553. }
  1554. $now = time();
  1555. $expireTime = $now + 1800;
  1556. $updateData = [];
  1557. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  1558. $oldOrderSn = $orderSn;
  1559. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  1560. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1561. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1562. $params = [
  1563. 'appid' => 'OP00002119',
  1564. 'serial_no' => '018b08cfddbd',
  1565. 'merchant_no' => $shop->lklSjNo,
  1566. 'term_no' => $shop->lklScanTermNo,
  1567. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1568. 'lklCertificatePath' => $lklCertificatePath,
  1569. ];
  1570. $laResource = new Lakala($params);
  1571. $closeParams = [
  1572. 'orderSn' => $oldOrderSn,
  1573. ];
  1574. $response = $laResource->close($closeParams);
  1575. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  1576. $msg = $response['msg'] ?? '';
  1577. $lklSjNo = $shop->lklSjNo ?? '';
  1578. noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . '。商户号:' . $lklSjNo, '15280215347');
  1579. util::fail('出错了哦,请重新下一单');
  1580. }
  1581. $orderSn = orderSn::getOrderSn();
  1582. $updateData['orderSn'] = $orderSn;
  1583. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  1584. } else {
  1585. //已请求的不能再修改价格
  1586. $updateData['modPrice'] = 0;
  1587. }
  1588. if (empty($order['deadline'])) {
  1589. $updateData['deadline'] = $expireTime;
  1590. }
  1591. if (!empty($updateData)) {
  1592. OrderService::updateById($orderId, $updateData);
  1593. }
  1594. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1595. $sjExtend = WxOpenClass::getMallWxInfo();
  1596. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1597. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1598. $params = [
  1599. 'appid' => 'OP00002119',
  1600. 'serial_no' => '018b08cfddbd',
  1601. 'merchant_no' => $shop->lklSjNo,
  1602. 'term_no' => $shop->lklScanTermNo,
  1603. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1604. 'lklCertificatePath' => $lklCertificatePath,
  1605. ];
  1606. $laResource = new Lakala($params);
  1607. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  1608. $wxParams = [
  1609. 'orderSn' => $orderSn,
  1610. 'amount' => $totalFee,
  1611. 'capitalType' => $capitalType,
  1612. 'notifyUrl' => $notifyUrl,
  1613. 'wxAppId' => $sjExtend['miniAppId'],
  1614. 'openId' => $openId,
  1615. 'subject' => $name,
  1616. 'couponId' => $couponId,
  1617. ];
  1618. $response = $laResource->driveWxPay($wxParams);
  1619. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  1620. $errMsg = $response['msg'] ?? '';
  1621. noticeUtil::push($errMsg, '15280215347');
  1622. util::fail('支付失败');
  1623. }
  1624. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  1625. $appId = $newParams['app_id'] ?? '';
  1626. $nonceStr = $newParams['nonce_str'] ?? '';
  1627. $paySign = $newParams['pay_sign'] ?? '';
  1628. $package = $newParams['package'] ?? '';
  1629. $signType = $newParams['sign_type'] ?? '';
  1630. $timeStamp = $newParams['time_stamp'] ?? '';
  1631. $new = [
  1632. 'id' => $orderId,
  1633. 'appId' => $appId,
  1634. 'nonceStr' => $nonceStr,
  1635. 'paySign' => $paySign,
  1636. 'package' => $package,
  1637. 'signType' => $signType,
  1638. 'timeStamp' => $timeStamp,
  1639. 'orderSn' => $orderSn,
  1640. ];
  1641. util::success($new);
  1642. }
  1643. //快捷付款订单
  1644. public function actionFastPay()
  1645. {
  1646. ini_set('date.timezone', 'Asia/Shanghai');
  1647. $post = Yii::$app->request->post();
  1648. $payWay = $post['payWay'] ?? 0;
  1649. $shopId = $this->shopId;
  1650. $shop = $this->shop;
  1651. if (empty($shop)) {
  1652. util::fail('没有门店信息');
  1653. }
  1654. $customId = $this->customId;
  1655. $custom = $this->custom;
  1656. $hdId = $this->hdId;
  1657. $hd = $this->hd;
  1658. if (empty($customId) || empty($hdId)) {
  1659. //考虑没有登录时的付款
  1660. $defaultCustomId = $shop->defaultCustomId ?? 0;
  1661. if (empty($defaultCustomId)) {
  1662. util::fail('请设置快捷开单的客户');
  1663. }
  1664. $customId = $defaultCustomId;
  1665. $custom = CustomClass::getById($defaultCustomId, true);
  1666. if (empty($custom)) {
  1667. util::fail('无效的快捷客户');
  1668. }
  1669. $hdId = $custom->hdId;
  1670. $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
  1671. if (empty($hd)) {
  1672. util::fail('没有花店信息呢!');
  1673. }
  1674. }
  1675. $post['hdId'] = $hdId;
  1676. $post['hdName'] = $hd->name ?? '';
  1677. $customName = $custom->name ?? '';
  1678. $customPy = $custom->py ?? '';
  1679. $post['customName'] = $customName;
  1680. $post['customNamePy'] = $customPy;
  1681. $post['shopId'] = $shopId;
  1682. $post['mainId'] = $this->mainId;
  1683. $post['customId'] = $customId;
  1684. $prePrice = round($post['prePrice'], 2);
  1685. $actPrice = $prePrice;
  1686. if ($actPrice <= 0) {
  1687. util::fail('请填写付款金额');
  1688. }
  1689. $post['actPrice'] = $actPrice;
  1690. $post['userId'] = $this->userId;
  1691. $now = time();
  1692. $expireTime = $now + 300;//订单5分钟后过期
  1693. $post['createTime'] = date("Y-m-d H:i:s", $now);
  1694. $post['deadline'] = date("Y-m-d H:i:s", $expireTime);
  1695. $order = ScanPayClass::addOrder($post);
  1696. $orderId = $order->id ?? 0;
  1697. $orderSn = $order->orderSn ?? '';
  1698. $capitalType = dict::getDict('capitalType', 'scanPay', 'id');
  1699. if ($payWay == 0) {
  1700. //微信
  1701. $name = '购买鲜花,扫码付款';
  1702. $totalFee = $actPrice;
  1703. $user = UserService::getById($this->userId);
  1704. //小程序使用miniOpenId
  1705. $openId = $user['miniOpenId'];
  1706. if (empty($openId)) {
  1707. $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
  1708. }
  1709. if (empty($openId)) {
  1710. util::fail('没有微信信息');
  1711. }
  1712. $sjExtend = WxOpenClass::getMallWxInfo();
  1713. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1714. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1715. $params = [
  1716. 'appid' => 'OP00002119',
  1717. 'serial_no' => '018b08cfddbd',
  1718. 'merchant_no' => $shop->lklSjNo,
  1719. 'term_no' => $shop->lklScanTermNo,
  1720. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1721. 'lklCertificatePath' => $lklCertificatePath,
  1722. ];
  1723. $laResource = new Lakala($params);
  1724. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  1725. $wxParams = [
  1726. 'orderSn' => $orderSn,
  1727. 'amount' => $totalFee,
  1728. 'capitalType' => $capitalType,
  1729. 'notifyUrl' => $notifyUrl,
  1730. 'wxAppId' => $sjExtend['miniAppId'],
  1731. 'openId' => $openId,
  1732. 'subject' => $name,
  1733. 'couponId' => 0,
  1734. ];
  1735. $response = $laResource->driveWxPay($wxParams);
  1736. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  1737. $errMsg = $response['msg'] ?? '';
  1738. noticeUtil::push($errMsg, '15280215347');
  1739. util::fail('支付失败');
  1740. }
  1741. $newParams = $response['resp_data']['acc_resp_fields'] ?? [];
  1742. $appId = $newParams['app_id'] ?? '';
  1743. $nonceStr = $newParams['nonce_str'] ?? '';
  1744. $paySign = $newParams['pay_sign'] ?? '';
  1745. $package = $newParams['package'] ?? '';
  1746. $signType = $newParams['sign_type'] ?? '';
  1747. $timeStamp = $newParams['time_stamp'] ?? '';
  1748. $new = [
  1749. 'id' => $orderId,
  1750. 'appId' => $appId,
  1751. 'nonceStr' => $nonceStr,
  1752. 'paySign' => $paySign,
  1753. 'package' => $package,
  1754. 'signType' => $signType,
  1755. 'timeStamp' => $timeStamp,
  1756. 'orderSn' => $orderSn,
  1757. ];
  1758. util::success($new);
  1759. } elseif ($payWay == 1) {
  1760. //支付宝
  1761. $totalFee = $actPrice;
  1762. $subject = '购买鲜花,扫码付款';
  1763. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1764. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1765. $params = [
  1766. 'appid' => 'OP00002119',
  1767. 'serial_no' => '018b08cfddbd',
  1768. 'merchant_no' => $shop->lklSjNo,
  1769. 'term_no' => $shop->lklB2BTermNo,
  1770. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1771. 'lklCertificatePath' => $lklCertificatePath,
  1772. ];
  1773. $laResource = new Lakala($params);
  1774. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
  1775. $cashParams = [
  1776. 'orderSn' => $orderSn,
  1777. 'amount' => $totalFee,
  1778. 'capitalType' => $capitalType,
  1779. 'notifyUrl' => $notifyUrl,
  1780. 'subject' => $subject,
  1781. ];
  1782. $response = $laResource->cashierPay($cashParams);
  1783. if (!isset($response['code']) || $response['code'] != '000000') {
  1784. util::fail('支付失败了');
  1785. }
  1786. $url = $response['resp_data']['counter_url'] ?? '';
  1787. if (empty($url)) {
  1788. util::fail('支付失败');
  1789. }
  1790. util::success(['url' => $url]);
  1791. } elseif ($payWay == 2) {
  1792. //余额支付
  1793. util::fail('暂不支持');
  1794. } else {
  1795. util::fail('无效的支付方式');
  1796. }
  1797. }
  1798. //订单列表 ssh 2019.12.12
  1799. public function actionList()
  1800. {
  1801. $get = Yii::$app->request->get();
  1802. $status = $get['status'] ?? 0;
  1803. $hdId = $get['hdId'] ?? 0;
  1804. $userId = $this->userId;
  1805. $where = ['userId' => $userId];
  1806. if (!empty($status)) {
  1807. $where['status'] = $status;
  1808. }
  1809. if (!empty($hdId)) {
  1810. $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
  1811. if (empty($hd)) {
  1812. util::fail('无效的花店');
  1813. }
  1814. if ($hd['userId'] != $userId) {
  1815. util::fail('不是你的花店');
  1816. }
  1817. $where['hdId'] = $hdId;
  1818. }
  1819. $list = OrderService::getOrderList($where);
  1820. util::success($list);
  1821. }
  1822. //订单评价
  1823. public function actionComment()
  1824. {
  1825. $post = Yii::$app->request->post();
  1826. $id = $post['id'];
  1827. $order = OrderClass::getById($id);
  1828. if ($order['grade'] > 0) {
  1829. util::fail('您已经评过了');
  1830. }
  1831. OrderService::comment($post);
  1832. util::complete('提交成功');
  1833. }
  1834. //订单详情 ssh 2019.12.16
  1835. public function actionDetail()
  1836. {
  1837. $id = Yii::$app->request->get('id', 0);
  1838. $detail = OrderClass::getOrderById($id);
  1839. $userId = $this->userId;
  1840. if ($detail['userId'] != $userId) {
  1841. util::fail('不是你的单,不能查看');
  1842. }
  1843. $shOrderMap = [];
  1844. if ($detail['hasForward'] == 1) {
  1845. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1846. }
  1847. $detail['shOrderMap'] = $shOrderMap;
  1848. //是否显示余额支付按钮 ssh 20260120
  1849. $hd = $this->hd;
  1850. $balance = $hd->balance ?? 0;
  1851. $showYePay = $balance > 0 ? 1 : 0;
  1852. $detail['showYePay'] = $showYePay;
  1853. $detail['balance'] = $balance;
  1854. $detail['rechargeWeal'] = $this->shop->rechargeWeal; //是否开启余额支付
  1855. // 与 RefundController::canApplyRefund 对齐,供详情页「申请售后」显隐
  1856. $detail['distOrderSettled'] = DistributionOrderClass::isDistOrderSettled((int)$id) ? 1 : 0;
  1857. $detail['canApplyRefund'] = $this->canApplyRefundForDetail($detail) ? 1 : 0;
  1858. // 配送方式名称:xhPsMethod.name(style = 订单 sendType)
  1859. $detail['psMethodName'] = $this->resolvePsMethodName($detail);
  1860. util::success($detail);
  1861. }
  1862. /**
  1863. * 解析订单配送方式名称(xhPsMethod.name,无记录时回退字典默认名)
  1864. * @param array $order 订单详情
  1865. * @return string
  1866. */
  1867. protected function resolvePsMethodName($order)
  1868. {
  1869. $mainId = (int)($order['mainId'] ?? 0);
  1870. $style = (int)($order['sendType'] ?? 0);
  1871. if ($mainId > 0) {
  1872. $psMethod = PsMethodClass::getByCondition([
  1873. 'mainId' => $mainId,
  1874. 'style' => $style,
  1875. ]);
  1876. if (!empty($psMethod['name'])) {
  1877. return (string)$psMethod['name'];
  1878. }
  1879. }
  1880. $default = dict::getDict('shMethod', $style);
  1881. return (string)($default['name'] ?? '');
  1882. }
  1883. /**
  1884. * 订单详情是否可申请售后(与 mall RefundController::canApplyRefund 规则一致)
  1885. * @param array $order 订单详情
  1886. * @return bool
  1887. */
  1888. protected function canApplyRefundForDetail($order)
  1889. {
  1890. if ((int)($order['payStatus'] ?? 0) !== 1) {
  1891. return false;
  1892. }
  1893. $status = (int)($order['status'] ?? 0);
  1894. if (in_array($status, [HdOrderClass::ORDER_STATUS_UN_PAY, HdOrderClass::ORDER_STATUS_CANCEL, 6], true)) {
  1895. return false;
  1896. }
  1897. if ((int)($order['forward'] ?? 0) === 1) {
  1898. return false;
  1899. }
  1900. $apply = MallRefundApplyClass::getLatestByOrderId((int)($order['id'] ?? 0));
  1901. if (!empty($apply) && (int)($apply['status'] ?? -1) === MallRefundApplyClass::STATUS_PENDING) {
  1902. return false;
  1903. }
  1904. if (DistributionOrderClass::isDistOrderSettled((int)($order['id'] ?? 0))) {
  1905. return false;
  1906. }
  1907. $could = bcsub((string)($order['orderPrice'] ?? 0), (string)($order['tkPrice'] ?? 0), 2);
  1908. if (bccomp($could, '0', 2) <= 0) {
  1909. return false;
  1910. }
  1911. return true;
  1912. }
  1913. //获取详情 ssh 20220512
  1914. public function actionInfo()
  1915. {
  1916. $sn = Yii::$app->request->get('orderSn', '');
  1917. $detail = OrderClass::getOrderBySn($sn);
  1918. util::success($detail);
  1919. }
  1920. }