OrderController.php 114 KB

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