OrderController.php 103 KB

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