OrderController.php 99 KB

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