OrderController.php 68 KB

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