OrderController.php 79 KB

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