OrderController.php 69 KB

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