OrderController.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizHd\purchase\classes\PurchaseClass;
  6. use bizHd\purchase\services\PurchaseService;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use bizGhs\order\classes\OrderClass;
  10. use bizGhs\order\services\OrderService;
  11. use bizHd\saas\services\RegionService;
  12. use bizGhs\product\classes\ProductClass;
  13. use common\components\baiduAip;
  14. use common\components\dict;
  15. use common\components\dateUtil;
  16. use common\components\freight;
  17. use common\components\httpUtil;
  18. use common\components\noticeUtil;
  19. use common\components\oss;
  20. use common\components\payUtil;
  21. use common\components\qrCodeUtil;
  22. use Yii;
  23. use common\components\util;
  24. use biz\shop\classes\ShopAdminClass;
  25. use biz\notice\classes\NoticeClass;
  26. use biz\wx\classes\WxMessageClass;
  27. use biz\shop\classes\ShopClass;
  28. use common\components\lakala\Lakala;
  29. class OrderController extends BaseController
  30. {
  31. public $guestAccess = ['create-order', 'order-relate', 'fast-pay', 'info'];
  32. public function actionAllFh()
  33. {
  34. $post = Yii::$app->request->post();
  35. $ids = $post['ids'] ?? '';
  36. if (empty($ids)) {
  37. util::fail('请选择要合并发货的订单');
  38. }
  39. $arr = explode(',', $ids);
  40. if (empty($arr)) {
  41. util::fail('请选择要合并发货的订单哦');
  42. }
  43. $fhWl = $post['fhWl'] ?? '';
  44. $fhWlNo = $post['fhWlNo'] ?? '';
  45. $fhType = 0;
  46. $params = [
  47. 'fhType' => $fhType,
  48. 'fhWl' => $fhWl,
  49. 'fhWlNo' => $fhWlNo,
  50. ];
  51. $connection = Yii::$app->db;
  52. $transaction = $connection->beginTransaction();
  53. try {
  54. $all = OrderClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true);
  55. foreach ($all as $order) {
  56. if ($order->mainId != $this->mainId) {
  57. util::fail('不是你的订单哦');
  58. }
  59. OrderClass::orderFh($order, $params, true);
  60. }
  61. $transaction->commit();
  62. util::complete();
  63. } catch (\Exception $e) {
  64. $transaction->rollBack();
  65. Yii::error("操作失败原因:" . $e->getMessage());
  66. util::fail('操作失败');
  67. }
  68. }
  69. //合并打印 ssh 20230929
  70. public function actionMergePrint()
  71. {
  72. $post = Yii::$app->request->post();
  73. $ids = $post['ids'] ?? '';
  74. if (empty($ids)) {
  75. util::fail('请选择要合并打印的订单');
  76. }
  77. $arr = explode(',', $ids);
  78. if (empty($arr)) {
  79. util::fail('请选择要合并打印的订单哦');
  80. }
  81. if (getenv('YII_ENV') == 'production') {
  82. if ($this->mainId != 10536 && $this->mainId != 50) {
  83. util::fail('功能开发中');
  84. }
  85. } else {
  86. if ($this->mainId != 11) {
  87. //util::fail('功能开发中');
  88. }
  89. }
  90. OrderClass::mergePrintOrder($arr, $this->mainId);
  91. util::complete('打印成功');
  92. }
  93. //发货 ssh 20230613
  94. public function actionFh()
  95. {
  96. $post = Yii::$app->request->post();
  97. $id = $post['id'] ?? '';
  98. $order = OrderClass::getById($id, true);
  99. OrderClass::valid($order, $this->shopId);
  100. $fhWl = $post['fhWl'] ?? '';
  101. $fhWlNo = $post['fhWlNo'] ?? '';
  102. $fhType = $post['fhType'] ?? '';
  103. $params = [
  104. 'fhType' => $fhType,
  105. 'fhWl' => $fhWl,
  106. 'fhWlNo' => $fhWlNo,
  107. ];
  108. $connection = Yii::$app->db;
  109. $transaction = $connection->beginTransaction();
  110. try {
  111. OrderClass::orderFh($order, $params);
  112. $transaction->commit();
  113. //小程序通知发货
  114. \bizHd\notice\classes\NoticeClass::orderFhMiniNotice($order);
  115. util::complete();
  116. } catch (\Exception $e) {
  117. $transaction->rollBack();
  118. Yii::error("操作失败原因:" . $e->getMessage());
  119. util::fail('操作失败');
  120. }
  121. }
  122. //修改分工 ssh 20221129
  123. public function actionChangeWorker()
  124. {
  125. $post = Yii::$app->request->post();
  126. $id = $post['id'] ?? 0;
  127. $shopAdminId = $post['shopAdminId'] ?? 0;
  128. $shopAdminName = $post['shopAdminName'] ?? '';
  129. $order = OrderClass::getById($id, true);
  130. OrderClass::valid($order, $this->shopId);
  131. $preShopAdminId = $order->shopAdminId ?? 0;
  132. if (!empty($preShopAdminId)) {
  133. $shopAdmin = $this->shopAdmin;
  134. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  135. util::fail('管理员才能操作');
  136. }
  137. }
  138. $order->shopAdminId = $shopAdminId;
  139. $order->shopAdminName = $shopAdminName;
  140. $order->save();
  141. util::complete();
  142. }
  143. //预订单到货 ssh 20220321
  144. public function actionArrival()
  145. {
  146. $post = Yii::$app->request->post();
  147. $id = $post['id'] ?? 0;
  148. $connection = Yii::$app->db;
  149. $transaction = $connection->beginTransaction();
  150. try {
  151. $order = OrderClass::getById($id, true);
  152. OrderClass::valid($order, $this->shopId);
  153. $post['shopAdminId'] = $this->shopAdminId;
  154. $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
  155. OrderService::arrival($order, $post);
  156. $transaction->commit();
  157. util::complete();
  158. } catch (\Exception $e) {
  159. $transaction->rollBack();
  160. Yii::error("操作失败原因:" . $e->getMessage());
  161. util::fail('操作失败');
  162. }
  163. }
  164. //到货获取订单详情 ssh 20220323
  165. public function actionArrivalDetail()
  166. {
  167. $get = Yii::$app->request->get();
  168. $id = $get['id'] ?? 0;
  169. $info = OrderClass::getById($id);
  170. OrderClass::valid($info, $this->shopId);
  171. $showItemData = OrderClass::getOriginalShowItem(true, $info);
  172. $itemList = $showItemData['list'] ?? [];
  173. $info['product'] = $itemList;
  174. $kiloFee = $this->shop->kiloFee ?? 0;
  175. $miniKilo = $this->shop->miniKilo ?? 0;
  176. $info['kiloFee'] = $kiloFee;
  177. $info['miniKilo'] = $miniKilo;
  178. util::success($info);
  179. }
  180. //支付宝扫码支付 ssh 20210103
  181. public function actionScanPayCheck()
  182. {
  183. $get = Yii::$app->request->get();
  184. $id = isset($get['id']) ? $get['id'] : 0;
  185. $order = OrderClass::getById($id, true);
  186. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
  187. util::success(['returnStatus' => 'SUCCESS']);
  188. }
  189. $deadline = $order->deadline ?? '';
  190. $deadTime = strtotime($deadline);
  191. $current = time();
  192. $diff = bcsub($deadTime, $current);
  193. if ($diff <= 60) {
  194. util::success(['returnStatus' => 'EXPIRE']);
  195. }
  196. util::success(['returnStatus' => 'FAILURE']);
  197. }
  198. //微信和支付宝扫码支付 ssh 20210103
  199. public function actionScanPay()
  200. {
  201. ini_set('date.timezone', 'Asia/Shanghai');
  202. header("Content-type: text/html; charset=utf-8");
  203. $get = Yii::$app->request->get();
  204. $id = isset($get['id']) ? $get['id'] : 0;
  205. $order = OrderClass::getById($id, true);
  206. if (isset($order->status) == false || $order->status != 1) {
  207. util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
  208. }
  209. OrderClass::valid($order, $this->shopId);
  210. $cgId = $order->purchaseId ?? 0;
  211. $cg = PurchaseClass::getById($cgId, true);
  212. $orderSn = $cg->orderSn ?? '';
  213. if (empty($orderSn)) {
  214. util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
  215. }
  216. $deadline = $cg->deadline;
  217. $current = date("Y-m-d H:i:s");
  218. if ((strtotime($deadline) + 20) < strtotime($current)) {
  219. util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
  220. }
  221. $totalFee = $cg->actPrice ?? 0;
  222. $subject = '购买鲜花';
  223. $totalAmount = $totalFee;
  224. $body = "到店订单";
  225. //标记为扫码支付 和 自取订单
  226. $order->codePay = 2;
  227. $order->sendType = OrderClass::SEND_TYPE_NO;
  228. $order->save();
  229. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  230. $cg->codePay = 2;
  231. $cg->save();
  232. $shop = $this->shop;
  233. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  234. $wxPayWay = dict::getDict('payWay', 'wxPay');
  235. $aliPayWay = dict::getDict('payWay', 'alipay');
  236. $payWay = Yii::$app->request->get('payWay', $wxPayWay);
  237. if ($payWay == $wxPayWay) {
  238. if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
  239. $url = $order->wxPayUrl;
  240. } else {
  241. util::fail('暂不支持');
  242. $merchantExtend = WxOpenClass::getWxInfo();
  243. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  244. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  245. $params = [
  246. 'appid' => 'OP00002119',
  247. 'serial_no' => '018b08cfddbd',
  248. 'merchant_no' => $shop->lklSjNo,
  249. 'term_no' => $shop->lklScanTermNo,
  250. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  251. 'lklCertificatePath' => $lklCertificatePath,
  252. ];
  253. $laResource = new Lakala($params);
  254. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  255. $wxParams = [
  256. 'orderSn' => $orderSn,
  257. 'amount' => $totalFee,
  258. 'capitalType' => $currentCapitalType,
  259. 'notifyUrl' => $notifyUrl,
  260. 'subject' => $subject,
  261. 'couponId' => 0,
  262. 'wxAppId' => $merchantExtend['miniAppId'],
  263. ];
  264. $response = $laResource->driveNativeWxPay($wxParams);
  265. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  266. $msg = $response['msg'] ?? '';
  267. noticeUtil::push($msg, '15280215347');
  268. util::fail('二维码生成失败');
  269. }
  270. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  271. if (empty($url)) {
  272. util::fail('二维码生成失败..');
  273. }
  274. $order->wxPayUrl = $url;
  275. $order->save();
  276. }
  277. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  278. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  279. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  280. }
  281. if ($payWay == $aliPayWay) {
  282. if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
  283. $url = $order->aliPayUrl;
  284. } else {
  285. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  286. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  287. $params = [
  288. 'appid' => 'OP00002119',
  289. 'serial_no' => '018b08cfddbd',
  290. 'merchant_no' => $shop->lklSjNo,
  291. 'term_no' => $shop->lklScanTermNo,
  292. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  293. 'lklCertificatePath' => $lklCertificatePath,
  294. ];
  295. $laResource = new Lakala($params);
  296. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  297. $aliParams = [
  298. 'orderSn' => $orderSn,
  299. 'amount' => $totalFee,
  300. 'capitalType' => $currentCapitalType,
  301. 'notifyUrl' => $notifyUrl,
  302. 'subject' => $subject,
  303. ];
  304. $response = $laResource->driveAliPay($aliParams);
  305. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  306. util::fail('二维码生成失败');
  307. }
  308. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  309. if (empty($url)) {
  310. util::fail('二维码生成失败..');
  311. }
  312. $order->aliPayUrl = $url;
  313. $order->save();
  314. }
  315. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  316. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  317. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  318. }
  319. util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
  320. }
  321. //微信和支付宝付款码支付复查 ssh 20211231
  322. public function actionCodePayCheck()
  323. {
  324. ini_set('date.timezone', 'Asia/Shanghai');
  325. header("Content-type: text/html; charset=utf-8");
  326. $get = Yii::$app->request->get();
  327. $id = isset($get['id']) ? $get['id'] : 0;
  328. $order = OrderClass::getById($id, true);
  329. if (empty($order)) {
  330. util::success(['returnStatus' => 'SUCCESS']);
  331. }
  332. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  333. util::complete('订单已付款');
  334. }
  335. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  336. util::complete('订单不是待付款状态');
  337. }
  338. OrderClass::valid($order, $this->shopId);
  339. $cgId = $order->purchaseId ?? 0;
  340. $cg = PurchaseClass::getById($cgId, true);
  341. $orderSn = $cg->orderSn ?? '';
  342. $totalFee = $cg->actPrice ?? 0;
  343. if (empty($orderSn)) {
  344. util::complete('没有找到采购单');
  345. }
  346. $connection = Yii::$app->db;
  347. $transaction = $connection->beginTransaction();
  348. try {
  349. $payWay = $cg->payWay ?? dict::getDict('payWay', 'wxPay');
  350. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  351. if ($payWay == dict::getDict('payWay', 'wxPay')) {
  352. //微信付款
  353. $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
  354. require_once($wx . '/lib/WxPay.Api.php');
  355. require_once($wx . '/example/WxPay.MicroPay.php');
  356. //获取微信商户号等信息
  357. $sjExtend = WxOpenClass::getGhsWxInfo();
  358. $microPay = new \MicroPay();
  359. $payReturn = $microPay->query($orderSn, $sjExtend);
  360. if ($payReturn["return_code"] == "SUCCESS" && $payReturn["result_code"] == "SUCCESS") {
  361. if ($payReturn["trade_state"] == "SUCCESS") {
  362. //支付成功
  363. $transactionId = $payReturn['transaction_id'] ?? '';
  364. $openId = $payReturn['openid'] ?? '';
  365. $aliUserId = '';
  366. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  367. $cg->codePay = 1;
  368. $cg->payOpenId = $openId;
  369. $cg->aliUserId = $aliUserId;
  370. //自取订单
  371. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  372. $cg->save();
  373. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  374. $order->codePay = 1;
  375. //自取订单
  376. $order->sendType = OrderClass::SEND_TYPE_NO;
  377. $order->save();
  378. $attach = '';
  379. payUtil::thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  380. $transaction->commit();
  381. $saleId = $order->id ?? 0;
  382. $order = OrderClass::getById($saleId, true);
  383. if (!empty($order)) {
  384. $shopId = $order->shopId ?? 0;
  385. $shop = ShopClass::getById($shopId, true);
  386. if (!empty($shop)) {
  387. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  388. }
  389. //订单生成时唤起在线打印
  390. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  391. if ($order->status != 1 && $order->status != 5) {
  392. OrderClass::onlinePrint($order);
  393. $order->printNum += 1;
  394. $order->save();
  395. }
  396. }
  397. ShopExtClass::ghsGatheringReport($order);
  398. }
  399. util::success(['returnStatus' => 'SUCCESS']);
  400. } else if ($payReturn["trade_state"] == "USERPAYING") {
  401. //用户支付中
  402. util::complete('正在付款,请稍候..');
  403. }
  404. }
  405. if ($payReturn["err_code"] == "ORDERNOTEXIST") {
  406. //交易订单号不存在
  407. util::complete('订单没有付款');
  408. } else {
  409. util::complete('系统错误,请稍候再试');
  410. }
  411. } elseif ($payWay == dict::getDict('payWay', 'alipay')) {
  412. //支付宝付款
  413. $aliF2F = Yii::getAlias("@vendor/alipayF2F");
  414. require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
  415. require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
  416. // $aliPId = '2017041906821571';
  417. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFXBrmdKjAcRJ8Q7ZHUmzIqAV+IMV+RD4J5mZHeJgdAECgYEA8J+Hp1M6eYbT4CPLXa//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA4NRPxmXvIjjmLb1Ft1qwHuyv3vvWhi50foGZXNEnBcfP/OkfyBDDpOEu34GZBMXK9ykHBs1l93OEFGXh7AwW0Lp5lARahBEfBZgPjq5yPO8TOJZrb5hVcuvoDdGjxpRh93XDnQDhWS/1IvUcBLcIsTcnVvfrkX4NLxF/W0CgYEAxamG+gD4rBQBwMImsRN+/2MV7M//iEUG+0qPeXeI/7rv9wUP3etMlwl48qSKNxj37xxN2ksa/Acxu/VZhu6XqKO3VUX+IWFQdaNGh2F13iLozIDLQOtKw3WfcjOq0xpZ5pwXq0RI8iSw+IUhyD8EHNZW2qU8CiRBhyt6hsywqQECgYBa8+06FAachI/XqWfF/UvcDdJ5AkS9/L8SvmmdsSkItjSIkfLHAqdxkbwl6Vu6kUOX/PJIFZjuAWTZFl4xBFNgFYj01uZHnnT6cnIp6HteD2CAqTSFAMqgfFWoL6zoaYAmJBnxO4oZPTYI+ilnQcts5VLFaChx0GCvS2BZgy2W0QKBgQDjP2VtRq4aVSLUq2z1KIDI7GJBbOM5KSW1OEj4sfEdViozPh3Ar/FQWiij1oCZF+iJdKkonHoDbDd+Q0ykcpQ+5Gv07iiT8wJYFR/0j8g2kfql7bVQhGSBeBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==';
  418. // $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB';
  419. $aliPId = '2021003122664465';
  420. $aliKey = 'MIIEpAIBAAKCAQEAnefrChYa5FUbGTlZNMTDNG531WrVP+TBPw3/hSmycRlBE/1sg9EryM0S3a9OQKQenRdYOoalqkkBuzt41ygJUC5hfNeaiV2OzphIiAyxUaiL1mSftP5B8joBN3HGG2AKbcvKlWcFoeiGY4ZmV/K0t3fqj/uPP6N/pEtnx6X4Ifgz4WGCDKUXKqT1Pyk2rqyIpel2EYk+HtC+9iicfac9kKQQiksDopb7sYosttdk64Dmjp2nMLDSpR+KOZUaqB39MEeHcJGeTzdVrp+Z9wW/NcJzSkSUb9juA0YjmogdbiKltykVHTbP6J0uPyByvzfyyY22QPqwNPiIPbCN6H543QIDAQABAoIBAQCO0+rOecYjSDO1siDVUTC8KTutR+/R1klRjojUWy3zjQNHYJAZ/0ZaX9wzttDSOWETeL0uWwJYL6coQxf/jVA3PWyirqYyn/R/PFFG9iwhj5HE/8lRvjXKMttM2lV2B34HaDE6yC/ZDmkYdsX1wSvjU81QJRuiVXIsGqSpep8hoVvVAn5sjvoC+zBSUaCsYy+7v7IXc6L8f/oLCBXY1r5j/+F/XFU1uFv4j162eRShQs6jQyVqQGLGCy4sSujj+8mpd6uCyJSIGJQHJlaN6cibTYStU/Z9+I/AP/+wQPVx31OwEC5J2xBfSHsezMsHSF7HQnfpQSz5AsOYZ3MOkiglAoGBAPV8sZz3C1gQ6WX5eKZE7PEUSxvAHsP+X6AAA6sWfH4cZq1uGJXgiDpTqN5dOqfNpNAU8gBDNTx4xUZ+cDuDH4WYxqkCe3CDdL97QmXDl2PnNvCKgHl735g3U1v3kCXgUAfBomc/xEIDguiEtsjPpknfjte/HmDE0zrWMOAQkJqXAoGBAKSrD5ryiVREpBmUohsI1g+e7BVR2nAtGYiquXIk2lkk5eQVO1yDh/LOU0jf8kI+UyRv16fANBjXqVc/twG016US5FNPV6fSllevsr0V020QemInO0+yJnTojSAfcayLroQId8Y3nPqVPpKMwvjvV7r50nGCCqXBtQsF4KITRzqrAoGAZBNyYNgBguRaEd1Sxw2gPmOUfvqiUCo6F4MJ+8xN8idn4FnaofcH8ic613PQPqpB/yYaxeqgIEfnvGY9ILXCuvbePfYqFmMwzALWvZ+v7uVKa2M7HstWCrq7O+m/lQFN/ut8ZnUDcBn4WwwHa/PjCYietetO2gpDRmAdSqrWGH8CgYBkwp+r6pkJzW60kHSZIlEKAe7oJMwLNC2ZqQ4MwGwzfBaH+E34kCuR8ZqYzyAIVOa/Nwi5By1Zvi1KzBwJmUUTJ3o7WCOE96EzSrmOZlqXNCwO/36Vh6dshhhE/birIlXJSP0xdzpBQy2ksyli9eGy8cdJ2Y72Wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  421. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  422. $config = array(
  423. //签名方式,默认为RSA2(RSA2048)
  424. 'sign_type' => "RSA2",
  425. //支付宝公钥
  426. 'alipay_public_key' => $aliPublicKey,
  427. //商户私钥
  428. 'merchant_private_key' => $aliKey,
  429. //编码格式
  430. 'charset' => "UTF-8",
  431. //支付宝网关
  432. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  433. //应用ID
  434. 'app_id' => $aliPId,
  435. //异步通知地址,只有扫码支付预下单可用
  436. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  437. //最大查询重试次数
  438. 'MaxQueryRetry' => "10",
  439. //查询间隔
  440. 'QueryDuration' => "3"
  441. );
  442. //构造查询业务请求参数对象
  443. $queryContentBuilder = new \AlipayTradeQueryContentBuilder();
  444. $queryContentBuilder->setOutTradeNo($orderSn);
  445. //初始化类对象,调用queryTradeResult方法获取查询应答
  446. $queryResponse = new \AlipayTradeService($config);
  447. $queryResult = $queryResponse->queryTradeResult($queryContentBuilder);
  448. if ($queryResult->getTradeStatus() == 'SUCCESS') {
  449. $respond = $queryResult->getResponse();
  450. $openId = '';
  451. $aliUserId = $respond->buyer_user_id ?? '';
  452. $transactionId = $respond->trade_no ?? '';
  453. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  454. $cg->codePay = 1;
  455. $cg->payOpenId = $openId;
  456. $cg->aliUserId = $aliUserId;
  457. //自取订单
  458. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  459. $cg->save();
  460. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  461. $order->codePay = 1;
  462. //自取订单
  463. $order->sendType = OrderClass::SEND_TYPE_NO;
  464. $order->save();
  465. $attach = '';
  466. payUtil::thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  467. $transaction->commit();
  468. $saleId = $order->id ?? 0;
  469. $order = OrderClass::getById($saleId, true);
  470. if (!empty($order)) {
  471. $shopId = $order->shopId ?? 0;
  472. $shop = ShopClass::getById($shopId, true);
  473. if (!empty($shop)) {
  474. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  475. }
  476. //订单生成时唤起在线打印
  477. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  478. if ($order->status != 1 && $order->status != 5) {
  479. OrderClass::onlinePrint($order);
  480. $order->printNum += 1;
  481. $order->save();
  482. }
  483. }
  484. ShopExtClass::ghsGatheringReport($order);
  485. }
  486. util::success(['returnStatus' => 'SUCCESS']);
  487. }
  488. } else {
  489. util::fail('还没有付款哦');
  490. }
  491. } catch (\Exception $e) {
  492. $transaction->rollBack();
  493. Yii::error("支付失败原因:" . $e->getMessage());
  494. util::fail('支付失败');
  495. }
  496. }
  497. //微信和支付宝付款码支付 ssh 2021.4.11
  498. public function actionCodePay()
  499. {
  500. ini_set('date.timezone', 'Asia/Shanghai');
  501. header("Content-type: text/html; charset=utf-8");
  502. $get = Yii::$app->request->get();
  503. $id = isset($get['id']) ? $get['id'] : 0;
  504. $order = OrderClass::getById($id, true);
  505. if (isset($order->status) == false || $order->status != 1) {
  506. util::fail('不是待付款订单');
  507. }
  508. OrderClass::valid($order, $this->shopId);
  509. $cgId = $order->purchaseId ?? 0;
  510. $cg = PurchaseClass::getById($cgId, true);
  511. $orderSn = $cg->orderSn ?? '';
  512. if (empty($orderSn)) {
  513. util::fail('没有找到采购单');
  514. }
  515. //付款码
  516. $authCode = (string)$get['authCode'] ?? '';
  517. if (empty($authCode)) {
  518. util::fail('支付失败');
  519. }
  520. $deadline = $cg->deadline;
  521. $current = date("Y-m-d H:i:s");
  522. if ((strtotime($deadline) + 20) < strtotime($current)) {
  523. util::fail('订单已经失效');
  524. }
  525. $totalFee = $cg->actPrice ?? 0;
  526. $connection = Yii::$app->db;
  527. $transaction = $connection->beginTransaction();
  528. try {
  529. $subject = '购买商品';
  530. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  531. $wxPayWay = dict::getDict('payWay', 'wxPay');
  532. $order->payWay = $wxPayWay;
  533. $order->save();
  534. $cg->payWay = $wxPayWay;
  535. $cg->save();
  536. $shop = $this->shop;
  537. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  538. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  539. $params = [
  540. 'appid' => 'OP00002119',
  541. 'serial_no' => '018b08cfddbd',
  542. 'merchant_no' => $shop->lklSjNo,
  543. 'term_no' => $shop->lklScanTermNo,
  544. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  545. 'lklCertificatePath' => $lklCertificatePath,
  546. ];
  547. $laResource = new Lakala($params);
  548. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  549. $scanParams = [
  550. 'orderSn' => $orderSn,
  551. 'amount' => $totalFee,
  552. 'capitalType' => $capitalType,
  553. 'notifyUrl' => $notifyUrl,
  554. 'subject' => $subject,
  555. 'authCode' => $authCode,
  556. ];
  557. $response = $laResource->scanPay($scanParams);
  558. print_r($response);die;
  559. if (isset($res["return_code"]) && $res["return_code"] == "SUCCESS" && isset($res["result_code"]) && $res["result_code"] == 'SUCCESS') {
  560. $transactionId = $res['transaction_id'] ?? '';
  561. $openId = $res['openid'] ?? '';
  562. $aliUserId = '';
  563. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  564. $cg->codePay = 1;
  565. $cg->payOpenId = $openId;
  566. $cg->aliUserId = $aliUserId;
  567. //自取订单
  568. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  569. $cg->save();
  570. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  571. $order->codePay = 1;
  572. //自取订单
  573. $order->sendType = OrderClass::SEND_TYPE_NO;
  574. $order->save();
  575. $attach = '';
  576. payUtil::thirdPay($wxPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  577. $transaction->commit();
  578. $saleId = $order->id ?? 0;
  579. $order = OrderClass::getById($saleId, true);
  580. if (!empty($order)) {
  581. $shopId = $order->shopId ?? 0;
  582. $shop = ShopClass::getById($shopId, true);
  583. if (!empty($shop)) {
  584. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  585. }
  586. //订单生成时唤起在线打印
  587. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  588. if ($order->status != 1 && $order->status != 5) {
  589. OrderClass::onlinePrint($order);
  590. $order->printNum += 1;
  591. $order->save();
  592. }
  593. }
  594. ShopExtClass::ghsGatheringReport($order);
  595. }
  596. util::success(['returnStatus' => 'SUCCESS']);
  597. } else {
  598. Yii::info(json_encode($res));
  599. $errCode = $res['err_code'] ?? '';
  600. $msg = '';
  601. if ($errCode == 'NOTENOUGH') {
  602. $msg = '余额不足';
  603. }
  604. if ($errCode == 'USERPAYING') {
  605. $msg = '等待客户输入支付密码';
  606. }
  607. util::success(['returnStatus' => 'FAILURE'], $msg);
  608. }
  609. } catch (\Exception $e) {
  610. $transaction->rollBack();
  611. Yii::error("支付失败原因:" . $e->getMessage());
  612. util::fail('支付失败');
  613. }
  614. }
  615. //订单列表 ssh 2021.1.20
  616. public function actionList()
  617. {
  618. $get = Yii::$app->request->get();
  619. $status = $get['status'] ?? 0;
  620. if (!empty($status)) {
  621. $where['status'] = $status;
  622. }
  623. $where['sjId'] = $this->sjId;
  624. if (isset($get['shopId'])) {
  625. $shopId = $get['shopId'] ?? 0;
  626. if (!empty($shopId)) {
  627. $where['shopId'] = $this->shopId;
  628. }
  629. } else {
  630. $where['shopId'] = $this->shopId;
  631. }
  632. $searchTime = $get['searchTime'] ?? '';
  633. if (!empty($searchTime)) {
  634. $startTime = $get['startTime'] ?? '';
  635. $endTime = $get['endTime'] ?? '';
  636. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  637. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  638. }
  639. $name = $get['name'] ?? '';
  640. if (!empty($name)) {
  641. $searchType = $get['searchType'] ?? 0;
  642. if (empty($searchType)) {
  643. //订单编号
  644. if (strpos($name, 'XSD') === 0) {
  645. $where['orderSn'] = $name;
  646. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  647. $where['customNamePy'] = ['like', $name];
  648. } else {
  649. $where['customName'] = ['like', $name];
  650. }
  651. } elseif ($searchType == 1) {
  652. $where['sendNum'] = $name;
  653. } else {
  654. }
  655. }
  656. if (isset($get['customId']) && !empty($get['customId'])) {
  657. $where['customId'] = $get['customId'];
  658. }
  659. if (isset($get['ids']) && !empty($get['ids'])) {
  660. $stringIds = $get['ids'];
  661. $newIds = explode(',', $stringIds);
  662. $where['id'] = ['in', $newIds];
  663. }
  664. $respond = OrderClass::getOrderList($where);
  665. $respond['shop'] = $this->shop;
  666. $respond['shopExt'] = $this->shopExt;
  667. util::success($respond);
  668. }
  669. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  670. public function actionNewOrderList()
  671. {
  672. $get = Yii::$app->request->get();
  673. $where['shopId'] = $this->shopId;
  674. /*$status = $get['status'] ?? 0;
  675. if (!empty($status)) {
  676. $where['status'] = $status;
  677. }*/
  678. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  679. if (isset($get['type'])) {
  680. $type = $get['type'];
  681. if ($type == 1) { // 今日实收
  682. $get['searchTime'] = 'today';
  683. $where['debt'] = 0;
  684. $where['debtPrice'] = '0.00';
  685. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  686. } elseif ($type == 2) { // 今日欠款
  687. $get['searchTime'] = 'today';
  688. $where['debt'] = 1;
  689. } elseif ($type == 3) { // 总欠款
  690. $where['debt'] = 1;
  691. } else {
  692. util::fail('查询的订单类别不存在');
  693. }
  694. }
  695. $searchTime = $get['searchTime'] ?? '';
  696. if (!empty($searchTime)) {
  697. $startTime = '';
  698. $endTime = '';
  699. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  700. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  701. }
  702. $name = $get['name'] ?? '';
  703. if (!empty($name)) {
  704. $searchType = $get['searchType'] ?? 0;
  705. if (empty($searchType)) {
  706. //订单编号
  707. if (strpos($name, 'XSD') === 0) {
  708. $where['orderSn'] = $name;
  709. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  710. $where['customNamePy'] = ['like', $name];
  711. } else {
  712. $where['customName'] = ['like', $name];
  713. }
  714. } elseif ($searchType == 1) {
  715. $where['sendNum'] = $name;
  716. } else {
  717. util::fail('搜索的订单类别不存在');
  718. }
  719. }
  720. $respond = OrderClass::getOrderList($where);
  721. $respond['shop'] = $this->shop;
  722. $respond['shopExt'] = $this->shopExt;
  723. $respond['type'] = $type; //把查询类别返回
  724. util::success($respond);
  725. }
  726. //商城下单操作 ssh 2021.1.14
  727. public function actionCreateOrder()
  728. {
  729. $post = Yii::$app->request->post();
  730. $shopId = $this->shopId;
  731. $customId = $post['customId'] ?? 0;
  732. $post['customId'] = $customId;
  733. //开单必须选客户
  734. if (empty($customId)) {
  735. util::fail('请选择客户');
  736. }
  737. $custom = CustomClass::getCustom($customId);
  738. if (empty($custom)) {
  739. util::fail('请选客户哦');
  740. }
  741. if ($customId != 5405 && $customId != 4091 && $customId != 8080 && $customId != 8081) {
  742. //除了花样年华、惠雅鲜花、天天鲜花和美天鲜花,批发店不能给已开批发店的零售客户开单,同理,采购也是要限制的。
  743. //审核入库的功能开通之后就可以用起来
  744. $customShopId = $custom['shopId'] ?? 0;
  745. if (!empty($customShopId)) {
  746. $customShop = ShopClass::getById($customShopId, true);
  747. if (isset($customShop->pfShopId) && !empty($customShop->pfShopId)) {
  748. util::fail('此客户开了批发店,暂不能直接给他开单');
  749. }
  750. }
  751. }
  752. CustomClass::valid($custom, $this->shopId);
  753. if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  754. util::fail('不能给自己的零售店开单');
  755. }
  756. $post['ghsId'] = $custom['ghsId'] ?? 0;
  757. $post['customMobile'] = $custom['mobile'] ?? '';
  758. $customName = $custom['name'] ?? '';
  759. $post['customName'] = $customName;
  760. $post['customNamePy'] = $custom['py'] ?? '';
  761. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  762. $post['province'] = $custom['province'] ?? '';
  763. $post['city'] = $custom['city'] ?? '';
  764. $post['dist'] = $custom['dist'] ?? '';
  765. $post['address'] = $custom['address'] ?? '';
  766. $post['floor'] = $custom['floor'] ?? '';
  767. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  768. $post['showAddress'] = $custom['showAddress'] ?? '';
  769. $post['long'] = $custom['long'] ?? '';
  770. $post['lat'] = $custom['lat'] ?? '';
  771. $shopAdmin = $this->shopAdmin;
  772. $shopAdminId = $this->shopAdminId;
  773. $shopAdminName = $shopAdmin->name ?? '';
  774. if (isset($post['getStaffId']) == true && !empty($post['getStaffId'])) {
  775. $getStaffName = $post['getStaffName'] ?? '';
  776. $shopAdminId = $post['getStaffId'];
  777. $shopAdminName = $getStaffName;
  778. }
  779. //开单人和收款人必定是同个人
  780. $post['shopAdminId'] = $shopAdminId;
  781. $post['shopAdminName'] = $shopAdminName;
  782. $post['getStaffId'] = $shopAdminId;
  783. $post['getStaffName'] = $shopAdminName;
  784. $post['sjId'] = $this->sjId;
  785. $post['shopId'] = $shopId;
  786. $post['mainId'] = $this->mainId;
  787. $post['fromType'] = 1;
  788. $post['expressId'] = $post['expressId'] ?? 0;
  789. $post['book'] = $post['book'] ?? 0;
  790. $sendType = $post['sendType'] ?? 0;
  791. $transType = $post['transType'] ?? 0;
  792. $shop = $this->shop;
  793. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  794. //昆明发往全国
  795. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  796. $post['sendCost'] = $sendCost;
  797. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  798. $post['packCost'] = $packCost;
  799. $post['transType'] = $transType;
  800. $post['localOrder'] = 1;
  801. } else {
  802. //同步配送
  803. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  804. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  805. util::fail('填了运费,请选择代叫跑腿');
  806. }
  807. $post['sendCost'] = $sendCost;
  808. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  809. }
  810. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  811. $post['debt'] = OrderClass::DEBT_NO;
  812. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  813. $post['debt'] = OrderClass::DEBT_YES;
  814. }
  815. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  816. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  817. //util::fail('没有权限');
  818. }
  819. }
  820. //多颜色数据整理
  821. $colorItem = $post['xj'] ?? [];
  822. $newXj = [];
  823. if (!empty($colorItem)) {
  824. $colorData = json_decode($colorItem, true);
  825. if (!empty($colorData) && is_array($colorData)) {
  826. foreach ($colorData as $colorInfo) {
  827. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  828. $colorList = $colorInfo['list'] ?? [];
  829. if (!empty($colorList)) {
  830. foreach ($colorList as $colorItemKey => $colorItem) {
  831. $newXj[$ptItemId][] = $colorItem;
  832. }
  833. }
  834. }
  835. }
  836. }
  837. $post['xj'] = $newXj;
  838. $productJson = $post['product'] ?? '';
  839. if (empty($productJson)) {
  840. util::fail('请选择花材');
  841. }
  842. $productList = json_decode($productJson, true);
  843. if (empty($productList)) {
  844. util::fail('请选择花材');
  845. }
  846. $dealPrice = $post['dealPrice'] ?? 0;
  847. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  848. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  849. if (empty($itemInfo)) {
  850. util::fail('请选择花材哦');
  851. }
  852. //判断花材有效性
  853. foreach ($itemInfo as $itemData) {
  854. if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
  855. util::fail('只能选择同一家的商品哈');
  856. }
  857. }
  858. //开单提交订单时,别人修改价格,暂成提交价格不是真实卖价问题解决!!
  859. if ($dealPrice == 0) {
  860. $diff = [];
  861. $priceMap = CustomClass::$levelPriceKeyMap;
  862. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  863. $level = $custom['level'] ?? 1;
  864. foreach ($productList as $currentProduct) {
  865. $currentPrice = $currentProduct['price'] ?? 0;
  866. $currentId = $currentProduct['productId'] ?? 0;
  867. $systemInfo = $itemInfo[$currentId] ?? [];
  868. $name = $systemInfo['name'] ?? '';
  869. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  870. if (floatval($currentPrice) != floatval($systemPrice)) {
  871. $diff[] = [
  872. 'name' => $name,
  873. 'price' => $systemPrice,
  874. 'kdPrice' => $currentPrice,
  875. ];
  876. }
  877. }
  878. if (!empty($diff)) {
  879. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  880. }
  881. }
  882. //4秒内不允许重复开单
  883. $staffId = $this->shopAdminId ?? 0;
  884. $cacheKey = 'ghs_create_order_' . $staffId . '_' . $customId;
  885. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  886. if (!empty($has)) {
  887. util::fail('请稍等');
  888. }
  889. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  890. $connection = Yii::$app->db;//事务处理
  891. $transaction = $connection->beginTransaction();
  892. try {
  893. $post['product'] = $productList;
  894. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  895. $time = time();
  896. $hasTime = dict::getDict('order_pay_has_time');
  897. $totalTime = bcadd($time, $hasTime);
  898. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  899. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  900. $transaction->commit();
  901. $saleId = $return->id ?? 0;
  902. $order = OrderClass::getById($saleId, true);
  903. if (!empty($order)) {
  904. $cgId = $order->purchaseId ?? 0;
  905. $cg = PurchaseClass::getById($cgId, true);
  906. $cgShopId = $cg->shopId ?? 0;
  907. $cgShop = ShopClass::getById($cgShopId, true);
  908. if ($order->status != 1 && $order->status != 5) {
  909. if (!empty($cgShop)) {
  910. //采购成功通知客户
  911. $cgNoticeRespond = \bizHd\notice\classes\NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  912. if (isset($cgNoticeRespond['hasNotice']) && $cgNoticeRespond['hasNotice'] == 1) {
  913. $order->hasNoticeCustom = 1;
  914. $order->save();
  915. }
  916. }
  917. }
  918. $shopId = $order->shopId ?? 0;
  919. $shop = ShopClass::getById($shopId, true);
  920. if (isset($order->payStatus) && $order->payStatus == 1) {
  921. if (!empty($shop)) {
  922. //花店采购供货商端收到微信通知
  923. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  924. $noticeText = json_encode(['orderId' => $saleId]);
  925. $noticeKey = "hdCgNoticeGhs";
  926. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  927. }
  928. }
  929. //订单生成时唤起在线打印
  930. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  931. if ($order->status != 1 && $order->status != 5) {
  932. OrderClass::onlinePrint($order);
  933. $order->printNum += 1;
  934. $order->save();
  935. }
  936. }
  937. if ($order->status != 1 && $order->status != 5) {
  938. //花店采购供货商端收到APP通知
  939. //NoticeClass::ghsNewOrderNotice($order);
  940. }
  941. //前台提醒出示付款码
  942. if (isset($order->status) && $order->status == 1) {
  943. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  944. ShopExtClass::ghsPleasePayReport($order);
  945. }
  946. }
  947. }
  948. util::success($return);
  949. } catch (\Exception $e) {
  950. $transaction->rollBack();
  951. Yii::error("下单失败原因:" . $e->getMessage());
  952. noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
  953. util::fail('下单失败');
  954. }
  955. }
  956. //修改订单 ssh 20210810
  957. public function actionUpdateOrder()
  958. {
  959. $post = Yii::$app->request->post();
  960. util::fail('订单不可修改');
  961. //PC端开单
  962. if (isset($post['clearType'])) {
  963. $clearType = $post['clearType'];
  964. if ($clearType == OrderClass::CLEAR_DEBT) {
  965. $post['debt'] = OrderClass::DEBT_YES;
  966. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  967. } else {
  968. $post['debt'] = OrderClass::DEBT_NO;
  969. }
  970. }
  971. //员工不能开已收款订单
  972. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  973. if ($debt == OrderClass::DEBT_NO) {
  974. $shopAdmin = $this->shopAdmin;
  975. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  976. util::fail('不能开已收款订单');
  977. }
  978. }
  979. //PC端开单
  980. if (isset($post['getType'])) {
  981. util::fail('暂不支持PC端修改订单');
  982. $getType = $post['getType'];
  983. //自取
  984. if ($getType == 1) {
  985. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  986. } else {
  987. //选择配送时,在发货时让商家自己再确认一下用什么方式
  988. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  989. }
  990. }
  991. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  992. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  993. $post['debt'] = OrderClass::DEBT_NO;
  994. }
  995. $id = $post['id'] ?? 0;
  996. $order = OrderClass::getLockById($id);
  997. if (empty($order)) {
  998. util::fail('没有找到订单');
  999. }
  1000. OrderClass::valid($order, $this->shopId);
  1001. unset($post['id']);
  1002. $shopAdmin = $this->shopAdmin;
  1003. $post['shopAdminId'] = $this->shopAdminId;
  1004. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1005. $post['fromType'] = 1;
  1006. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1007. $productJson = $post['product'] ?? '';
  1008. if (empty($productJson)) {
  1009. util::fail('请选择花材');
  1010. }
  1011. $productList = json_decode($productJson, true);
  1012. if (empty($productList)) {
  1013. util::fail('请选择花材');
  1014. }
  1015. $connection = Yii::$app->db;//事务处理
  1016. $transaction = $connection->beginTransaction();
  1017. try {
  1018. //判断花材有效性
  1019. ProductClass::valid($productList, $this->mainId);
  1020. $post['product'] = $productList;
  1021. //商家开单订单有效期,到期记欠款
  1022. $validTime = dict::getDict('order_pay_has_time');
  1023. $current = time() + $validTime;
  1024. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1025. $upData = [
  1026. 'payWay' => $post['payWay'],
  1027. 'sendType' => $post['sendType'],
  1028. 'debt' => $post['debt'],
  1029. 'needPrint' => $post['needPrint'],
  1030. 'modifyPrice' => $post['modifyPrice'],
  1031. 'shopAdminId' => $post['shopAdminId'],
  1032. 'shopAdminName' => $post['shopAdminName'],
  1033. 'fromType' => 1,
  1034. 'sendCost' => $post['sendCost'],
  1035. 'product' => $post['product'],
  1036. 'deadline' => $post['deadline'],
  1037. 'debt' => $post['debt'],
  1038. ];
  1039. $return = OrderService::updateOrder($order, $upData);
  1040. $transaction->commit();
  1041. util::success($return);
  1042. } catch (\Exception $e) {
  1043. $transaction->rollBack();
  1044. Yii::error("下单失败原因:" . $e->getMessage());
  1045. util::fail('下单失败');
  1046. }
  1047. }
  1048. //取消订单 shizhongqi 20220619
  1049. public function actionCancelOrder()
  1050. {
  1051. $post = Yii::$app->request->post();
  1052. $id = $post['orderId'] ?? 0;
  1053. if (empty($id)) {
  1054. util::fail('请选择订单');
  1055. }
  1056. $order = OrderClass::getById($id, true);
  1057. if (empty($order)) {
  1058. util::fail('请选择订单...');
  1059. }
  1060. OrderClass::valid($order, $this->shopId);
  1061. if (isset($order->status) == false || $order->status != 1) {
  1062. util::fail('不是待付款状态,无法取消');
  1063. }
  1064. $purchaseId = $order->purchaseId ?? 0;
  1065. $purchase = PurchaseClass::getById($purchaseId);
  1066. if (empty($purchase)) {
  1067. util::fail('没有找到采购单');
  1068. }
  1069. $deadLineTime = strtotime($purchase['deadline']);
  1070. $diff = $deadLineTime - time();
  1071. if ($diff <= 60) {
  1072. util::fail('1分钟后订单将自动取消');
  1073. }
  1074. $connection = Yii::$app->db;//事务处理
  1075. $transaction = $connection->beginTransaction();
  1076. $orderSn = $purchase['orderSn'];
  1077. try {
  1078. $current = PurchaseClass::getById($purchaseId, true);
  1079. PurchaseService::expire($current);
  1080. $transaction->commit();
  1081. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1082. } catch (\Exception $e) {
  1083. $transaction->rollBack();
  1084. $msg = $e->getMessage();
  1085. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1086. }
  1087. util::complete();
  1088. }
  1089. //延期支付 ssh 2021.1.19
  1090. public function actionDebt()
  1091. {
  1092. $id = Yii::$app->request->get('id');
  1093. $order = OrderClass::getById($id, true);
  1094. OrderClass::valid($order, $this->shopId);
  1095. $payWay = dict::getDict('payWay', 'debtPay');
  1096. $cgId = $order->purchaseId ?? 0;
  1097. $cg = PurchaseClass::getById($cgId, true);
  1098. if (empty($cg)) {
  1099. util::fail('没有找到采购单');
  1100. }
  1101. PurchaseService::payAfter($cg, $payWay);
  1102. OrderService::payAfter($order, $payWay);
  1103. $order = OrderClass::getById($id, true);
  1104. if (!empty($order)) {
  1105. $shopId = $order->shopId ?? 0;
  1106. $shop = ShopClass::getById($shopId, true);
  1107. if (!empty($shop)) {
  1108. //花店采购供货商端微信收到通知
  1109. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1110. $noticeText = json_encode(['orderId' => $id]);
  1111. $noticeKey = "hdCgNoticeGhs";
  1112. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1113. }
  1114. //订单生成时唤起在线打印
  1115. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1116. if ($order->status != 1 && $order->status != 5) {
  1117. OrderClass::onlinePrint($order);
  1118. $order->printNum += 1;
  1119. $order->save();
  1120. }
  1121. }
  1122. if ($order->status != 1 && $order->status != 5) {
  1123. //花店采购供货商端APP收到通知
  1124. //NoticeClass::ghsNewOrderNotice($order);
  1125. }
  1126. }
  1127. util::complete();
  1128. }
  1129. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1130. public function actionWxPay()
  1131. {
  1132. ini_set('date.timezone', 'Asia/Shanghai');
  1133. $post = Yii::$app->request->post();
  1134. $couponId = $post['couponId'] ?? 0;
  1135. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1136. $order = OrderClass::getByOrderSn($orderSn);
  1137. if (empty($order)) {
  1138. util::fail('订单号无效');
  1139. }
  1140. $id = $order['id'];
  1141. //支付前验证订单有效性
  1142. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1143. util::fail('没有权限操作');
  1144. }
  1145. $name = $order['orderName'] ?? '购买商品';
  1146. $totalFee = $order['actPrice'];
  1147. //强制使用小程序的miniOpenId
  1148. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1149. if (empty($openId)) {
  1150. util::fail('没有找到openId');
  1151. }
  1152. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1153. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1154. $wxPayType = 0;
  1155. if (httpUtil::isMiniProgram()) {
  1156. $wxPayType = 1;
  1157. }
  1158. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1159. //订单30分钟后过期
  1160. $now = time();
  1161. $expireTime = $now + 1800;
  1162. $wx = Yii::getAlias("@vendor/weixin");
  1163. require_once($wx . '/lib/WxPay.Api.php');
  1164. require_once($wx . '/example/WxPay.JsApiPay.php');
  1165. $input = new \WxPayUnifiedOrder();
  1166. $input->SetBody($name);
  1167. $input->SetOut_trade_no($orderSn);
  1168. $input->SetTotal_fee($totalFee * 100);
  1169. $input->SetTime_start(date("YmdHis", $now));
  1170. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1171. $input->SetTime_expire(date("YmdHis", $expireTime));
  1172. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1173. $input->SetTrade_type("JSAPI");
  1174. //花卉宝代为申请的微信支付
  1175. //$sjExtend = $this->sjExtend->attributes;
  1176. $sjExtend = WxOpenClass::getGhsWxInfo();
  1177. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1178. $input->SetSub_openid($openId);
  1179. } else {
  1180. $input->SetOpenid($openId);
  1181. }
  1182. //强制使用小程序的miniAppId
  1183. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1184. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1185. $tools = new \JsApiPay();
  1186. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1187. $newParams = json_decode($jsApiParameters, true);
  1188. //微信不能修改价格
  1189. $current = date("Y-m-d H:i:s");
  1190. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1191. OrderClass::updateById($id, $updateData);
  1192. util::success($newParams);
  1193. }
  1194. //获取订单详情 ssh 2021.1.21
  1195. public function actionDetail()
  1196. {
  1197. $get = Yii::$app->request->get();
  1198. $id = $get['id'] ?? 0;
  1199. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1200. OrderClass::valid($info, $this->shopId);
  1201. //是否有云打印判断
  1202. $hasCloudPrint = 0;
  1203. $shopExt = $this->shopExt;
  1204. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1205. $hasCloudPrint = 1;
  1206. }
  1207. $info['hasCloudPrint'] = $hasCloudPrint;
  1208. $purchaseId = $info['purchaseId'] ?? 0;
  1209. $cg = PurchaseClass::getById($purchaseId);
  1210. $info['cgInfo'] = $cg;
  1211. //店长信息
  1212. $mainId = $cg['mainId'] ?? 0;
  1213. $superInfo = ShopAdminClass::getManager($mainId);
  1214. $info['customSuper'] = $superInfo;
  1215. util::success($info);
  1216. }
  1217. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1218. public function actionInfo()
  1219. {
  1220. $get = Yii::$app->request->get();
  1221. $id = $get['id'] ?? 0;
  1222. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1223. if (empty($info)) {
  1224. util::fail('没有找到订单');
  1225. }
  1226. //是否有云打印判断
  1227. $hasCloudPrint = 0;
  1228. $shopExt = $this->shopExt;
  1229. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1230. $hasCloudPrint = 1;
  1231. }
  1232. $info['hasCloudPrint'] = $hasCloudPrint;
  1233. $purchaseId = $info['purchaseId'] ?? 0;
  1234. $cg = PurchaseClass::getById($purchaseId);
  1235. $info['cgInfo'] = $cg;
  1236. //店长信息
  1237. $mainId = $cg['mainId'] ?? 0;
  1238. $superInfo = ShopAdminClass::getManager($mainId);
  1239. $info['customSuper'] = $superInfo;
  1240. util::success($info);
  1241. }
  1242. //自取免发货流程处理 ssh 2021.1.22
  1243. public function actionWithoutSend()
  1244. {
  1245. util::complete();
  1246. }
  1247. //本店送 ssh 2021.1.24
  1248. public function actionSelfSend()
  1249. {
  1250. $get = Yii::$app->request->get();
  1251. $id = isset($get['id']) ? $get['id'] : 0;
  1252. $info = OrderClass::getById($id, true);
  1253. OrderClass::valid($info->attributes, $this->shopId);
  1254. $connection = Yii::$app->db;
  1255. $transaction = $connection->beginTransaction();
  1256. try {
  1257. OrderClass::selfSend($info);
  1258. $transaction->commit();
  1259. } catch (\Exception $exception) {
  1260. $transaction->rollBack();
  1261. Yii::info("本店送操作报错:" . $exception->getMessage());
  1262. util::fail('操作失败');
  1263. }
  1264. util::complete();
  1265. }
  1266. //运费计算 ssh 2021.1.24
  1267. public function actionFreight()
  1268. {
  1269. //2021.3.28 接入达达
  1270. $get = Yii::$app->request->get();
  1271. $post = Yii::$app->request->post();
  1272. if (empty($get)) {
  1273. $get = $post;
  1274. }
  1275. $orderId = $get['id'] ?? 0; //订单ID
  1276. $customId = $get['customId'] ?? 0;
  1277. if (empty($orderId)) {
  1278. //自定义运费
  1279. //freight::getCost();
  1280. if (empty($customId)) {
  1281. util::fail("请选择客户");
  1282. }
  1283. $customInfo = CustomClass::getById($customId);
  1284. if (empty($customInfo)) {
  1285. util::fail('没有找到客户');
  1286. }
  1287. $shop = $this->shop;
  1288. //花材信息
  1289. $productJson = $get['product'] ?? '';
  1290. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1291. if (empty($productJson)) {
  1292. util::fail('请选择花材');
  1293. }
  1294. $productList = json_decode($productJson, true);
  1295. if (empty($productList)) {
  1296. util::fail('请选择花材');
  1297. }
  1298. $productList = ProductClass::mergeItemInfo($productList);
  1299. $weight = 0;
  1300. $price = 0;
  1301. $productData = ProductClass::getProductMapData($productList);
  1302. $bigNum = 0;
  1303. foreach ($productList as $key => $val) {
  1304. $productId = $val['productId'];
  1305. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1306. $bigNum += $val['bigNum'];
  1307. $weight = bcadd($w, $weight, 2);
  1308. $ratio = $productData[$productId]['ratio'] ?? 0;
  1309. //大小数量合并多少扎
  1310. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1311. //售卖价格
  1312. $itemPrice = $productData[$productId]['price'] ?? 0;
  1313. //合计价格
  1314. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1315. }
  1316. //没有经纬度的客户运费直接返回空 ssh 20210612
  1317. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1318. util::success(['sedCost' => '']);
  1319. }
  1320. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1321. util::success(['sedCost' => $cost]);
  1322. }
  1323. $province = $get['province'] ?? '';
  1324. $city = $get['city'] ?? '';
  1325. $address = $get['address'] ?? '';
  1326. $floor = $get['floor'] ?? '';
  1327. $customName = $get['customName'] ?? '';
  1328. $customMobile = $get['customMobile'] ?? '';
  1329. $fullAddress = $province . $city . $address . $floor;
  1330. $sendTime = $get['sendTime'] ?? '';
  1331. $lat = $get['lat'] ?? '';
  1332. $lng = $get['long'] ?? '';
  1333. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1334. util::fail('请填写客户地址');
  1335. }
  1336. ini_set('date.timezone', 'Asia/Shanghai');
  1337. if (!empty($sendTime)) {
  1338. //配送时间不为空
  1339. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1340. $sendTimeInt = strtotime($sendTime);
  1341. $now = time();
  1342. $diff = $sendTimeInt - $now;
  1343. //因服务器写入时间,改为至少提前6分钟
  1344. if ($diff <= 360) {
  1345. util::fail('配送时间至少提前6分钟');
  1346. }
  1347. } else {
  1348. //默认立即发送
  1349. $sendTime = 0;
  1350. }
  1351. //更新订单表
  1352. $info = OrderService::getOrderInfo($orderId);
  1353. OrderClass::valid($info, $this->shopId);
  1354. if ($sendTime) {
  1355. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1356. } else {
  1357. $sendTime = '0000-00-00 00:00:00';
  1358. }
  1359. $expressAddInfo = [
  1360. 'customName' => $customName,
  1361. 'customMobile' => $customMobile,
  1362. 'province' => $province,
  1363. 'city' => $city,
  1364. 'address' => $address,
  1365. 'floor' => $floor,
  1366. 'lat' => $lat,
  1367. 'long' => $lng,
  1368. 'sendTime' => $sendTime,
  1369. ];
  1370. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  1371. //计算运费
  1372. $info['province'] = $province;
  1373. $info['city'] = $city;
  1374. $info['address'] = $address;
  1375. $info['floor'] = $floor;
  1376. $info['fullAddress'] = $fullAddress;
  1377. $info['lat'] = $lat;
  1378. $info['long'] = $lng;
  1379. $info['sendTime'] = $expressAddInfo['sendTime'];
  1380. $res = DadaExpressServices::queryDeliverFee($info);
  1381. util::success(['sedCost' => $res['fee']]);
  1382. }
  1383. //发快递和第三方配送 ssh 2021.1.24
  1384. public function actionThirdSend()
  1385. {
  1386. $get = Yii::$app->request->get();
  1387. $id = isset($get['id']) ? $get['id'] : 0;
  1388. $info = OrderService::getById($id, true);
  1389. OrderClass::valid($info->attributes, $this->shopId);
  1390. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  1391. util::fail('请填写客户地址');
  1392. }
  1393. $connection = Yii::$app->db;
  1394. $transaction = $connection->beginTransaction();
  1395. try {
  1396. $respond = OrderClass::thirdSend($info, $get);
  1397. $transaction->commit();
  1398. util::success($respond);
  1399. } catch (\Exception $exception) {
  1400. $transaction->rollBack();
  1401. Yii::info("发快递操作报错:" . $exception->getMessage());
  1402. util::fail('操作失败' . $exception->getMessage());
  1403. }
  1404. }
  1405. //确认送达 ssh 2021.1.24
  1406. public function actionReach()
  1407. {
  1408. $get = Yii::$app->request->get();
  1409. $id = isset($get['id']) ? $get['id'] : 0;
  1410. $info = OrderClass::getById($id, true);
  1411. OrderClass::valid($info->attributes, $this->shopId);
  1412. $connection = Yii::$app->db;
  1413. $transaction = $connection->beginTransaction();
  1414. try {
  1415. OrderService::reach($info);
  1416. $transaction->commit();
  1417. } catch (\Exception $exception) {
  1418. $transaction->rollBack();
  1419. Yii::info("送达操作报错:" . $exception->getMessage());
  1420. util::fail('操作失败');
  1421. }
  1422. util::complete();
  1423. }
  1424. //下单要用到的相关信息 ssh 2019.12.6
  1425. public function actionOrderRelate()
  1426. {
  1427. $regionTree = RegionService::tree();
  1428. $shop = $this->shop->attributes;
  1429. $freight = ['first' => 5, 'add' => 2];
  1430. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1431. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1432. util::success($out);
  1433. }
  1434. //客户欠款的订单 ssh 2021.2.4
  1435. public function actionDebtList()
  1436. {
  1437. $get = Yii::$app->request->get();
  1438. $id = $get['id'] ?? 0;
  1439. $info = CustomClass::getCustom($id);
  1440. CustomClass::valid($info, $this->shopId);
  1441. $where = ['customId' => $id, 'debt' => 1];
  1442. $searchTime = $get['searchTime'] ?? '';
  1443. if (!empty($searchTime)) {
  1444. $startTime = $get['startTime'] ?? '';
  1445. $endTime = $get['endTime'] ?? '';
  1446. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1447. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1448. }
  1449. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
  1450. $result = ['customInfo' => $info, 'list' => $list];
  1451. util::success($result);
  1452. }
  1453. //更新打印次数
  1454. public function actionAddPrintNum()
  1455. {
  1456. $id = Yii::$app->request->get('id', 0);
  1457. $order = OrderClass::getById($id, true);
  1458. OrderClass::valid($order, $this->shopId);
  1459. $order->printNum += 1;
  1460. $order->save();
  1461. util::complete();
  1462. }
  1463. //打印订单 ssh 20210714
  1464. public function actionCloudPrintOrder()
  1465. {
  1466. $get = Yii::$app->request->get();
  1467. $id = $get['id'] ?? 0;
  1468. $showPrice = $get['showPrice'] ?? 1;
  1469. $order = OrderClass::getById($id, true);
  1470. OrderClass::valid($order, $this->shopId);
  1471. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  1472. util::fail('订单还没有付款');
  1473. }
  1474. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  1475. util::fail('订单已取消');
  1476. }
  1477. $ext = $this->shopExt;
  1478. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  1479. util::success(['hasNoPrint' => 1]);
  1480. }
  1481. OrderClass::onlinePrint($order, $showPrice);
  1482. $order->printNum += 1;
  1483. $order->save();
  1484. util::complete();
  1485. }
  1486. //订单确认完成 ssh 20210809
  1487. public function actionConfirmFinish()
  1488. {
  1489. $payWay = Yii::$app->request->get('payWay', -1);
  1490. $id = Yii::$app->request->get('id', 0);
  1491. $clearType = Yii::$app->request->get('clearType', 0);
  1492. $connection = Yii::$app->db;
  1493. $transaction = $connection->beginTransaction();
  1494. try {
  1495. $order = OrderClass::getById($id, true);
  1496. OrderClass::valid($order, $this->shopId);
  1497. $purchaseId = $order->purchaseId ?? 0;
  1498. $purchase = PurchaseClass::getById($purchaseId, true);
  1499. if (empty($purchase)) {
  1500. util::fail('没有采购信息');
  1501. }
  1502. if ($clearType == 1) {
  1503. //欠款
  1504. $payWay = dict::getDict('payWay', 'debtPay');
  1505. } elseif ($clearType == 2) {
  1506. //已收款
  1507. if ($payWay == -1) {
  1508. util::fail('请选择收款方式');
  1509. }
  1510. $shopAdmin = $this->shopAdmin;
  1511. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1512. util::fail('超管才能发起已收款');
  1513. }
  1514. } else {
  1515. util::fail('请选择结算方式');
  1516. }
  1517. //不需要打印
  1518. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  1519. $order->save();
  1520. //支付
  1521. PurchaseService::payAfter($purchase, $payWay);
  1522. OrderService::payAfter($order, $payWay);
  1523. //自己送
  1524. $info = OrderClass::getById($id, true);
  1525. OrderClass::selfSend($info);
  1526. //确认送达,并且不需要微信通知
  1527. Yii::$app->params['noNeedWxNotice'] = 1;
  1528. $info = OrderClass::getById($id, true);
  1529. OrderService::reach($info);
  1530. $transaction->commit();
  1531. util::complete('操作成功');
  1532. } catch (\Exception $exception) {
  1533. $transaction->rollBack();
  1534. Yii::info("确认完成订单报错:" . $exception->getMessage());
  1535. util::fail('操作失败');
  1536. }
  1537. }
  1538. //取消订单 ssh 20220110
  1539. public function actionCancel()
  1540. {
  1541. $shopAdmin = $this->shopAdmin;
  1542. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1543. util::fail('超管才能取消订单');
  1544. }
  1545. $id = Yii::$app->request->get('id');
  1546. $order = OrderClass::getById($id, true);
  1547. if ($order->orderType == 2) {
  1548. util::fail('客户下单,不能主动取消');
  1549. }
  1550. OrderClass::valid($order, $this->shopId);
  1551. OrderService::expire($order, true);
  1552. util::complete('已取消');
  1553. }
  1554. //获取收款语音播报地址 ssh 20211231
  1555. public function actionGetPayVoice()
  1556. {
  1557. $id = Yii::$app->request->get('id');
  1558. $order = OrderClass::getById($id, true);
  1559. $payWay = $order->payWay ?? 0;
  1560. $money = floatval($order->actPrice);
  1561. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  1562. $msg = $payment . '收款' . $money . '元';
  1563. $audio = baiduAip::transfer($msg, 4, 0);
  1564. //上传到oss
  1565. $file = time() . rand(10000, 999999) . '.mp3';
  1566. $filePath = 'tmp/arrival/money/' . $file;
  1567. oss::uploadTmpAudio($filePath, $audio);
  1568. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  1569. util::success(['url' => $url]);
  1570. }
  1571. }