OrderController.php 79 KB

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