OrderController.php 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415
  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. $get = Yii::$app->request->get();
  676. $export = $get['export'] ?? 0;
  677. $onlySend = $get['onlySend'] ?? 0;
  678. $staff = $this->shopAdmin;
  679. if (isset($staff->identity) && $staff->identity == 2) {
  680. //如果用于确认发货时要显出订单
  681. if($onlySend == 0){
  682. util::success(['list' => []]);
  683. }
  684. }
  685. $where['mainId'] = $this->mainId;
  686. $status = $get['status'] ?? 0;
  687. if (!empty($status)) {
  688. $where['status'] = $status;
  689. }
  690. $clearSign = $get['clearSign'] ?? -1;
  691. if ($clearSign > -1) {
  692. $where['clearSign'] = $clearSign;
  693. }
  694. $book = $get['book'] ?? -1;
  695. if ($book > -1) {
  696. $where['book'] = $book;
  697. }
  698. $searchTime = $get['searchTime'] ?? '';
  699. if (!empty($searchTime)) {
  700. $startTime = $get['startTime'] ?? '';
  701. $endTime = $get['endTime'] ?? '';
  702. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  703. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  704. }
  705. if ($export == 1) {
  706. ini_set('memory_limit', '2045M');
  707. set_time_limit(0);
  708. if (isset($where['payTime']) == false) {
  709. util::fail('请选时间段');
  710. }
  711. $start = $where['payTime'][1][0];
  712. $end = $where['payTime'][1][1];
  713. $monthTime = bcmul(31, 86400);
  714. $startArea = strtotime($start);
  715. $endArea = strtotime($end);
  716. $diff = bcsub($endArea, $startArea);
  717. if ($diff > $monthTime) {
  718. util::fail('最长可导出一个月');
  719. }
  720. }
  721. $name = $get['name'] ?? '';
  722. if (!empty($name)) {
  723. $searchType = $get['searchType'] ?? 0;
  724. if (empty($searchType)) {
  725. //订单编号
  726. if (strpos($name, 'XSD') === 0) {
  727. $where['orderSn'] = $name;
  728. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  729. $where['customNamePy'] = ['like', $name];
  730. } else {
  731. $where['customName'] = ['like', $name];
  732. }
  733. } elseif ($searchType == 1) {
  734. $where['sendNum'] = $name;
  735. } else {
  736. }
  737. }
  738. if (isset($get['customId']) && !empty($get['customId'])) {
  739. $where['customId'] = $get['customId'];
  740. }
  741. if (isset($get['ids']) && !empty($get['ids'])) {
  742. $stringIds = $get['ids'];
  743. $newIds = explode(',', $stringIds);
  744. $where['id'] = ['in', $newIds];
  745. }
  746. $respond = OrderClass::getOrderList($where);
  747. if ($export == 1) {
  748. OrderClass::exportOrderData($respond, $this->mainId);
  749. }
  750. $respond['shop'] = $this->shop;
  751. $respond['shopExt'] = $this->shopExt;
  752. util::success($respond);
  753. }
  754. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  755. public function actionNewOrderList()
  756. {
  757. $get = Yii::$app->request->get();
  758. $where['shopId'] = $this->shopId;
  759. /*$status = $get['status'] ?? 0;
  760. if (!empty($status)) {
  761. $where['status'] = $status;
  762. }*/
  763. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  764. if (isset($get['type'])) {
  765. $type = $get['type'];
  766. if ($type == 1) { // 今日实收
  767. $get['searchTime'] = 'today';
  768. $where['debt'] = 0;
  769. $where['debtPrice'] = '0.00';
  770. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  771. } elseif ($type == 2) { // 今日欠款
  772. $get['searchTime'] = 'today';
  773. $where['debt'] = 1;
  774. } elseif ($type == 3) { // 总欠款
  775. $where['debt'] = 1;
  776. } else {
  777. util::fail('查询的订单类别不存在');
  778. }
  779. }
  780. $searchTime = $get['searchTime'] ?? '';
  781. if (!empty($searchTime)) {
  782. $startTime = '';
  783. $endTime = '';
  784. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  785. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  786. }
  787. $name = $get['name'] ?? '';
  788. if (!empty($name)) {
  789. $searchType = $get['searchType'] ?? 0;
  790. if (empty($searchType)) {
  791. //订单编号
  792. if (strpos($name, 'XSD') === 0) {
  793. $where['orderSn'] = $name;
  794. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  795. $where['customNamePy'] = ['like', $name];
  796. } else {
  797. $where['customName'] = ['like', $name];
  798. }
  799. } elseif ($searchType == 1) {
  800. $where['sendNum'] = $name;
  801. } else {
  802. util::fail('搜索的订单类别不存在');
  803. }
  804. }
  805. $respond = OrderClass::getOrderList($where);
  806. $respond['shop'] = $this->shop;
  807. $respond['shopExt'] = $this->shopExt;
  808. $respond['type'] = $type; //把查询类别返回
  809. util::success($respond);
  810. }
  811. //商城下单操作 ssh 2021.1.14
  812. public function actionCreateOrder()
  813. {
  814. $post = Yii::$app->request->post();
  815. $shopId = $this->shopId;
  816. $customId = $post['customId'] ?? 0;
  817. $post['customId'] = $customId;
  818. //开单必须选客户
  819. if (empty($customId)) {
  820. util::fail('请选择客户');
  821. }
  822. $custom = CustomClass::getCustom($customId);
  823. if (empty($custom)) {
  824. util::fail('请选客户哦');
  825. }
  826. $shopAdmin = $this->shopAdmin;
  827. $shopAdminId = $this->shopAdminId;
  828. $shopAdminName = $shopAdmin->name ?? '';
  829. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  830. $createOrderCacheKey = 'ghs_custom_create_order_' . $customId . '_' . $shopAdminId;
  831. $has = Yii::$app->redis->executeCommand('GET', [$createOrderCacheKey]);
  832. if (!empty($has)) {
  833. util::fail('已提交过,5秒后再试');
  834. }
  835. Yii::$app->redis->executeCommand('SETEX', [$createOrderCacheKey, 5, 'has']);
  836. CustomClass::valid($custom, $this->shopId);
  837. if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  838. util::fail('不能给自己开单');
  839. }
  840. $post['ghsId'] = $custom['ghsId'] ?? 0;
  841. $post['customMobile'] = $custom['mobile'] ?? '';
  842. $customName = $custom['name'] ?? '';
  843. $post['customName'] = $customName;
  844. $post['customNamePy'] = $custom['py'] ?? '';
  845. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  846. $post['province'] = $custom['province'] ?? '';
  847. $post['city'] = $custom['city'] ?? '';
  848. $post['dist'] = $custom['dist'] ?? '';
  849. $post['address'] = $custom['address'] ?? '';
  850. $post['floor'] = $custom['floor'] ?? '';
  851. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  852. $post['showAddress'] = $custom['showAddress'] ?? '';
  853. $post['long'] = $custom['long'] ?? '';
  854. $post['lat'] = $custom['lat'] ?? '';
  855. if (isset($post['getStaffId']) == true && !empty($post['getStaffId'])) {
  856. $getStaffName = $post['getStaffName'] ?? '';
  857. $shopAdminId = $post['getStaffId'];
  858. $shopAdminName = $getStaffName;
  859. } else {
  860. if (getenv('YII_ENV') == 'production') {
  861. //鹏诚需要选择开单人
  862. if (in_array($this->mainId, [19606])) {
  863. util::fail('请选择开单人');
  864. }
  865. } else {
  866. if (in_array($this->mainId, [])) {
  867. util::fail('请选择开单人');
  868. }
  869. }
  870. }
  871. if (getenv('YII_ENV') == 'production') {
  872. //小向花卉开单售后控制
  873. if ($this->mainId == 23390) {
  874. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960, 28456, 31105, 28456, 31105])) {
  875. util::fail('你不能开单哦');
  876. }
  877. }
  878. }
  879. //开单人和收款人必定是同个人
  880. $post['shopAdminId'] = $shopAdminId;
  881. $post['shopAdminName'] = $shopAdminName;
  882. $post['getStaffId'] = $shopAdminId;
  883. $post['getStaffName'] = $shopAdminName;
  884. $post['sjId'] = $this->sjId;
  885. $post['shopId'] = $shopId;
  886. $post['mainId'] = $this->mainId;
  887. $post['fromType'] = 1;
  888. $post['expressId'] = $post['expressId'] ?? 0;
  889. $book = $post['book'] ?? 0;
  890. $post['book'] = $book;
  891. $sendType = $post['sendType'] ?? 0;
  892. $transType = $post['transType'] ?? 0;
  893. $shop = $this->shop;
  894. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  895. //昆明发往全国
  896. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  897. $post['sendCost'] = $sendCost;
  898. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  899. $post['packCost'] = $packCost;
  900. $post['transType'] = $transType;
  901. $post['localOrder'] = 1;
  902. } else {
  903. //同步配送
  904. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  905. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  906. util::fail('填了运费,请选择代叫跑腿');
  907. }
  908. $post['sendCost'] = $sendCost;
  909. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  910. }
  911. if ($book == 1) {
  912. $bookSn = $shop->bookSn ?? 0;
  913. if (empty($bookSn)) {
  914. util::fail('请开启预订');
  915. }
  916. $post['bookSn'] = $bookSn;
  917. }
  918. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  919. $post['debt'] = OrderClass::DEBT_NO;
  920. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  921. $post['debt'] = OrderClass::DEBT_YES;
  922. }
  923. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  924. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  925. //util::fail('没有权限');
  926. }
  927. }
  928. //多颜色数据整理
  929. $colorItem = $post['xj'] ?? [];
  930. $newXj = [];
  931. if (!empty($colorItem)) {
  932. $colorData = json_decode($colorItem, true);
  933. if (!empty($colorData) && is_array($colorData)) {
  934. foreach ($colorData as $colorInfo) {
  935. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  936. $colorList = $colorInfo['list'] ?? [];
  937. if (!empty($colorList)) {
  938. foreach ($colorList as $colorItemKey => $colorItem) {
  939. $newXj[$ptItemId][] = $colorItem;
  940. }
  941. }
  942. }
  943. }
  944. }
  945. $post['xj'] = $newXj;
  946. $productJson = $post['product'] ?? '';
  947. if (empty($productJson)) {
  948. util::fail('请选择花材');
  949. }
  950. $productList = json_decode($productJson, true);
  951. if (empty($productList)) {
  952. util::fail('请选择花材');
  953. }
  954. $dealPrice = $post['dealPrice'] ?? 0;
  955. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  956. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  957. if (empty($itemInfo)) {
  958. util::fail('请选择花材哦');
  959. }
  960. //判断花材有效性
  961. foreach ($itemInfo as $itemData) {
  962. if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
  963. util::fail('只能选择同一家的商品哈');
  964. }
  965. }
  966. //开单提交订单时,别人修改价格,暂成提交价格不是真实卖价问题解决!!
  967. if ($dealPrice == 0) {
  968. $diff = [];
  969. $priceMap = CustomClass::$levelPriceKeyMap;
  970. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  971. $level = $custom['level'] ?? 1;
  972. foreach ($productList as $currentKey => $currentProduct) {
  973. $currentPrice = $currentProduct['price'] ?? 0;
  974. $currentId = $currentProduct['productId'] ?? 0;
  975. $systemInfo = $itemInfo[$currentId] ?? [];
  976. $name = $systemInfo['name'] ?? '';
  977. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  978. if (floatval($currentPrice) != floatval($systemPrice)) {
  979. $diff[] = [
  980. 'name' => $name,
  981. 'price' => $systemPrice,
  982. 'kdPrice' => $currentPrice,
  983. ];
  984. }
  985. }
  986. if (!empty($diff)) {
  987. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  988. Yii::$app->redis->executeCommand('DEL', [$createOrderCacheKey]);
  989. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  990. }
  991. }
  992. if ($book == 1) {
  993. $post['hasPay'] = 2;
  994. $post['payWay'] = 0;
  995. }
  996. $historyDate = $post['historyDate'] ?? '';
  997. if (!empty($historyDate)) {
  998. if ($book == 1) {
  999. util::fail('预订单不能选订单日期');
  1000. }
  1001. if ($hasPay == 0) {
  1002. util::fail('扫码付不能选订单日期');
  1003. }
  1004. if (strtotime($historyDate) > strtotime(date("Y-m-d"))) {
  1005. util::fail('订单日期只能选历史时间');
  1006. }
  1007. }
  1008. $connection = Yii::$app->db;//事务处理
  1009. $transaction = $connection->beginTransaction();
  1010. try {
  1011. $post['product'] = $productList;
  1012. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  1013. $time = time();
  1014. $hasTime = dict::getDict('order_pay_has_time');
  1015. $totalTime = bcadd($time, $hasTime);
  1016. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  1017. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  1018. $transaction->commit();
  1019. $saleId = $return->id ?? 0;
  1020. $order = OrderClass::getById($saleId, true);
  1021. if (!empty($order)) {
  1022. $shopId = $order->shopId ?? 0;
  1023. $customId = $order->customId ?? 0;
  1024. $ghsId = $order->ghsId ?? 0;
  1025. $custom = CustomClass::getById($customId, true);
  1026. $date = date("Y-m-d H:i:s");
  1027. if (!empty($custom)) {
  1028. $custom->recentExpend = $date;
  1029. $custom->save();
  1030. }
  1031. $ghs = GhsClass::getById($ghsId, true);
  1032. if (!empty($ghs)) {
  1033. $ghs->recentExpend = $date;
  1034. $ghs->save();
  1035. }
  1036. $shop = ShopClass::getById($shopId, true);
  1037. if (isset($order->payStatus) && $order->payStatus == 1) {
  1038. if (!empty($shop)) {
  1039. //通知员工
  1040. $noticeText = json_encode(['orderId' => $saleId]);
  1041. $noticeKey = "hdCgNoticeGhs";
  1042. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1043. //通知花店
  1044. // $noticeText = json_encode(['id' => $order->purchaseId]);
  1045. // $noticeKey = "ghsKdNoticeHd";
  1046. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1047. }
  1048. }
  1049. //订单生成时唤起在线打印
  1050. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1051. //预订单开单不打小票,小向花卉不需要打小票
  1052. $mainId = $order->mainId ?? 0;
  1053. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1054. if ($order->status != 1 && $order->status != 5) {
  1055. OrderClass::onlinePrint($order);
  1056. $ext = $this->shopExt;
  1057. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1058. $order->printNum += 1;
  1059. $order->save();
  1060. }
  1061. }
  1062. }
  1063. }
  1064. //前台提醒出示付款码
  1065. if (isset($order->status) && $order->status == 1) {
  1066. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1067. ShopExtClass::ghsPleasePayReport($order);
  1068. }
  1069. }
  1070. }
  1071. util::success($return);
  1072. } catch (\Exception $e) {
  1073. $transaction->rollBack();
  1074. Yii::error("下单失败原因:" . $e->getMessage());
  1075. noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
  1076. util::fail('下单失败');
  1077. }
  1078. }
  1079. //修改订单 ssh 20210810
  1080. public function actionUpdateOrder()
  1081. {
  1082. $post = Yii::$app->request->post();
  1083. util::fail('订单不可修改');
  1084. //PC端开单
  1085. if (isset($post['clearType'])) {
  1086. $clearType = $post['clearType'];
  1087. if ($clearType == OrderClass::CLEAR_DEBT) {
  1088. $post['debt'] = OrderClass::DEBT_YES;
  1089. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1090. } else {
  1091. $post['debt'] = OrderClass::DEBT_NO;
  1092. }
  1093. }
  1094. //员工不能开已收款订单
  1095. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1096. if ($debt == OrderClass::DEBT_NO) {
  1097. $shopAdmin = $this->shopAdmin;
  1098. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1099. util::fail('不能开已收款订单');
  1100. }
  1101. }
  1102. //PC端开单
  1103. if (isset($post['getType'])) {
  1104. util::fail('暂不支持PC端修改订单');
  1105. $getType = $post['getType'];
  1106. //自取
  1107. if ($getType == 1) {
  1108. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1109. } else {
  1110. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1111. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1112. }
  1113. }
  1114. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1115. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1116. $post['debt'] = OrderClass::DEBT_NO;
  1117. }
  1118. $id = $post['id'] ?? 0;
  1119. $order = OrderClass::getLockById($id);
  1120. if (empty($order)) {
  1121. util::fail('没有找到订单');
  1122. }
  1123. OrderClass::valid($order, $this->shopId);
  1124. unset($post['id']);
  1125. $shopAdmin = $this->shopAdmin;
  1126. $post['shopAdminId'] = $this->shopAdminId;
  1127. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1128. $post['fromType'] = 1;
  1129. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1130. $productJson = $post['product'] ?? '';
  1131. if (empty($productJson)) {
  1132. util::fail('请选择花材');
  1133. }
  1134. $productList = json_decode($productJson, true);
  1135. if (empty($productList)) {
  1136. util::fail('请选择花材');
  1137. }
  1138. $connection = Yii::$app->db;//事务处理
  1139. $transaction = $connection->beginTransaction();
  1140. try {
  1141. //判断花材有效性
  1142. ProductClass::valid($productList, $this->mainId);
  1143. $post['product'] = $productList;
  1144. //商家开单订单有效期,到期记欠款
  1145. $validTime = dict::getDict('order_pay_has_time');
  1146. $current = time() + $validTime;
  1147. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1148. $upData = [
  1149. 'payWay' => $post['payWay'],
  1150. 'sendType' => $post['sendType'],
  1151. 'debt' => $post['debt'],
  1152. 'needPrint' => $post['needPrint'],
  1153. 'modifyPrice' => $post['modifyPrice'],
  1154. 'shopAdminId' => $post['shopAdminId'],
  1155. 'shopAdminName' => $post['shopAdminName'],
  1156. 'fromType' => 1,
  1157. 'sendCost' => $post['sendCost'],
  1158. 'product' => $post['product'],
  1159. 'deadline' => $post['deadline'],
  1160. 'debt' => $post['debt'],
  1161. ];
  1162. $return = OrderService::updateOrder($order, $upData);
  1163. $transaction->commit();
  1164. util::success($return);
  1165. } catch (\Exception $e) {
  1166. $transaction->rollBack();
  1167. Yii::error("下单失败原因:" . $e->getMessage());
  1168. util::fail('下单失败');
  1169. }
  1170. }
  1171. //取消预订单 ssh 20240503
  1172. public function actionCancelBookOrder()
  1173. {
  1174. $get = Yii::$app->request->get();
  1175. $id = $get['id'] ?? 0;
  1176. if (empty($id)) {
  1177. util::fail('请选择订单');
  1178. }
  1179. $order = OrderClass::getById($id, true);
  1180. if (empty($order)) {
  1181. util::fail('没有找到订单');
  1182. }
  1183. OrderClass::valid($order, $this->shopId);
  1184. if ($order->book == 0) {
  1185. util::fail('不是预订单');
  1186. }
  1187. if ($order->status != 2) {
  1188. util::fail('当前订单状态不能取消');
  1189. }
  1190. $purchaseId = $order->purchaseId ?? 0;
  1191. $purchase = PurchaseClass::getById($purchaseId, true);
  1192. if (empty($purchase)) {
  1193. util::fail('没有找到采购单');
  1194. }
  1195. $connection = Yii::$app->db;//事务处理
  1196. $transaction = $connection->beginTransaction();
  1197. try {
  1198. $order->status = 5;
  1199. $order->save();
  1200. $purchase->status = 5;
  1201. $purchase->save();
  1202. $transaction->commit();
  1203. util::complete('取消成功');
  1204. } catch (\Exception $e) {
  1205. $transaction->rollBack();
  1206. $msg = $e->getMessage();
  1207. $orderSn = $order->orderSn ?? '';
  1208. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1209. }
  1210. }
  1211. //取消订单 shizhongqi 20220619
  1212. public function actionCancelOrder()
  1213. {
  1214. $post = Yii::$app->request->post();
  1215. $id = $post['orderId'] ?? 0;
  1216. if (empty($id)) {
  1217. util::fail('请选择订单');
  1218. }
  1219. $order = OrderClass::getById($id, true);
  1220. if (empty($order)) {
  1221. util::fail('请选择订单...');
  1222. }
  1223. OrderClass::valid($order, $this->shopId);
  1224. if (isset($order->status) == false || $order->status != 1) {
  1225. util::fail('不是待付款状态,无法取消');
  1226. }
  1227. $purchaseId = $order->purchaseId ?? 0;
  1228. $purchase = PurchaseClass::getById($purchaseId);
  1229. if (empty($purchase)) {
  1230. util::fail('没有找到采购单');
  1231. }
  1232. $deadLineTime = strtotime($purchase['deadline']);
  1233. $diff = $deadLineTime - time();
  1234. if ($diff <= 60) {
  1235. util::fail('1分钟后订单将自动取消');
  1236. }
  1237. $connection = Yii::$app->db;//事务处理
  1238. $transaction = $connection->beginTransaction();
  1239. $orderSn = $purchase['orderSn'];
  1240. try {
  1241. $current = PurchaseClass::getById($purchaseId, true);
  1242. PurchaseService::expire($current);
  1243. $transaction->commit();
  1244. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1245. } catch (\Exception $e) {
  1246. $transaction->rollBack();
  1247. $msg = $e->getMessage();
  1248. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1249. }
  1250. util::complete();
  1251. }
  1252. //延期支付 ssh 2021.1.19
  1253. public function actionDebt()
  1254. {
  1255. $id = Yii::$app->request->get('id');
  1256. //4秒内不允许重复提交
  1257. $cacheKey = 'ghs_set_order_debt_' . $id;
  1258. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1259. if (!empty($has)) {
  1260. util::fail('请稍等');
  1261. }
  1262. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1263. $order = OrderClass::getById($id, true);
  1264. OrderClass::valid($order, $this->shopId);
  1265. $payWay = dict::getDict('payWay', 'debtPay');
  1266. $cgId = $order->purchaseId ?? 0;
  1267. $cg = PurchaseClass::getById($cgId, true);
  1268. if (empty($cg)) {
  1269. util::fail('没有找到采购单');
  1270. }
  1271. if ($order->book == 1) {
  1272. util::fail('预订单不能记欠款');
  1273. }
  1274. $connection = Yii::$app->db;
  1275. $transaction = $connection->beginTransaction();
  1276. try {
  1277. PurchaseService::payAfter($cg, $payWay);
  1278. OrderService::payAfter($order, $payWay);
  1279. $transaction->commit();
  1280. } catch (\Exception $exception) {
  1281. $transaction->rollBack();
  1282. Yii::info("延期支付报错:" . $exception->getMessage());
  1283. util::fail('操作失败');
  1284. }
  1285. $order = OrderClass::getById($id, true);
  1286. if (!empty($order)) {
  1287. $shopId = $order->shopId ?? 0;
  1288. $shop = ShopClass::getById($shopId, true);
  1289. if (!empty($shop)) {
  1290. //花店采购供货商端微信收到通知
  1291. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1292. $noticeText = json_encode(['orderId' => $id]);
  1293. $noticeKey = "hdCgNoticeGhs";
  1294. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1295. }
  1296. //订单生成时唤起在线打印
  1297. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1298. if ($order->status != 1 && $order->status != 5) {
  1299. OrderClass::onlinePrint($order);
  1300. $ext = $this->shopExt;
  1301. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1302. $order->printNum += 1;
  1303. $order->save();
  1304. }
  1305. }
  1306. }
  1307. if ($order->status != 1 && $order->status != 5) {
  1308. //花店采购供货商端APP收到通知
  1309. //NoticeClass::ghsNewOrderNotice($order);
  1310. }
  1311. }
  1312. util::complete();
  1313. }
  1314. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1315. public function actionWxPay()
  1316. {
  1317. ini_set('date.timezone', 'Asia/Shanghai');
  1318. $post = Yii::$app->request->post();
  1319. $couponId = $post['couponId'] ?? 0;
  1320. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1321. $order = OrderClass::getByOrderSn($orderSn);
  1322. if (empty($order)) {
  1323. util::fail('订单号无效');
  1324. }
  1325. $id = $order['id'];
  1326. //支付前验证订单有效性
  1327. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1328. util::fail('无法操作');
  1329. }
  1330. $name = $order['orderName'] ?? '购买商品';
  1331. $totalFee = $order['actPrice'];
  1332. //强制使用小程序的miniOpenId
  1333. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1334. if (empty($openId)) {
  1335. util::fail('没有找到openId');
  1336. }
  1337. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1338. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1339. $wxPayType = 0;
  1340. if (httpUtil::isMiniProgram()) {
  1341. $wxPayType = 1;
  1342. }
  1343. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1344. //订单30分钟后过期
  1345. $now = time();
  1346. $expireTime = $now + 1800;
  1347. $wx = Yii::getAlias("@vendor/weixin");
  1348. require_once($wx . '/lib/WxPay.Api.php');
  1349. require_once($wx . '/example/WxPay.JsApiPay.php');
  1350. $input = new \WxPayUnifiedOrder();
  1351. $input->SetBody($name);
  1352. $input->SetOut_trade_no($orderSn);
  1353. $input->SetTotal_fee($totalFee * 100);
  1354. $input->SetTime_start(date("YmdHis", $now));
  1355. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1356. $input->SetTime_expire(date("YmdHis", $expireTime));
  1357. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1358. $input->SetTrade_type("JSAPI");
  1359. //花卉宝代为申请的微信支付
  1360. //$sjExtend = $this->sjExtend->attributes;
  1361. $sjExtend = WxOpenClass::getGhsWxInfo();
  1362. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1363. $input->SetSub_openid($openId);
  1364. } else {
  1365. $input->SetOpenid($openId);
  1366. }
  1367. //强制使用小程序的miniAppId
  1368. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1369. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1370. $tools = new \JsApiPay();
  1371. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1372. $newParams = json_decode($jsApiParameters, true);
  1373. //微信不能修改价格
  1374. $current = date("Y-m-d H:i:s");
  1375. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1376. OrderClass::updateById($id, $updateData);
  1377. util::success($newParams);
  1378. }
  1379. //获取订单详情 ssh 2021.1.21
  1380. public function actionDetail()
  1381. {
  1382. $get = Yii::$app->request->get();
  1383. $id = $get['id'] ?? 0;
  1384. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1385. OrderClass::valid($info, $this->shopId);
  1386. //A4打印需要用到的数据
  1387. $customId = $info['customId'] ?? 0;
  1388. $remark = $info['remark'] ?? '';
  1389. $sendCost = $info['sendCost'] ?? 0;
  1390. $sendNum = $info['sendNum'] ?? '';
  1391. $packCost = $info['packCost'] ?? 0;
  1392. $staffName = $info['shopAdminName'] ?? '';
  1393. $ysName = '';
  1394. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  1395. if ($info['transType'] == 0) {
  1396. $ysName = '德邦空运';
  1397. }
  1398. if ($info['transType'] == 1) {
  1399. $ysName = '顺丰空运';
  1400. }
  1401. if ($info['transType'] == 2) {
  1402. $ysName = '冷链物流';
  1403. }
  1404. if ($info['transType'] == 3) {
  1405. $ysName = '航空物流';
  1406. }
  1407. if ($info['transType'] == 4) {
  1408. $ysName = '同城配送';
  1409. }
  1410. if ($info['transType'] == 5) {
  1411. $ysName = '到店自取';
  1412. }
  1413. } else {
  1414. }
  1415. $fullAddress = '';
  1416. if (getenv('YII_ENV') == 'production') {
  1417. //老油的要显示地址
  1418. if ($this->mainId == 20528) {
  1419. $fullAddress = $info['fullAddress'] ?? '';
  1420. }
  1421. } else {
  1422. if ($this->mainId == 644) {
  1423. $fullAddress = $info['fullAddress'] ?? '';
  1424. }
  1425. }
  1426. $custom = CustomClass::getById($customId, true);
  1427. if (empty($custom)) {
  1428. util::fail('没有找到客户');
  1429. }
  1430. $customName = $custom->name ?? '';
  1431. $customMobile = $custom->customMobile ?? '';
  1432. if (empty($customMobile)) {
  1433. $customShopId = $custom->shopId ?? 0;
  1434. $customShop = ShopClass::getById($customShopId, true);
  1435. if (!empty($customShop)) {
  1436. $customMobile = $customShop->mobile ?? '';
  1437. }
  1438. }
  1439. if (!empty($customMobile)) {
  1440. $customMobile = substr_replace($customMobile, '****', 3, 4);
  1441. }
  1442. $fullCustom = $customName . ' ' . $customMobile;
  1443. if ($this->mainId == 8164) {
  1444. //花大苪不显示客户名称
  1445. $fullCustom = '';
  1446. }
  1447. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  1448. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1449. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1450. $totalItemNum = 0;
  1451. $totalSmallItemNum = 0;
  1452. $table = [];
  1453. if (isset($info['product']) && !empty($info['product'])) {
  1454. foreach ($info['product'] as $key => $val) {
  1455. $currentName = $val['name'] ?? '';
  1456. $num = $val['xhNum'] ?? 0;
  1457. $refundNum = $val['refundNum'] ?? 0;
  1458. $num = bcsub($num, $refundNum);
  1459. $totalItemNum = bcadd($totalItemNum, $num);
  1460. $ratio = $val['ratio'] ?? 0;
  1461. $currentSmallNum = bcmul($num, $ratio);
  1462. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1463. $itemRemark = $val['remark'] ?? '';
  1464. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1465. $unitPrice = floatval($unitPrice);
  1466. $price = $val['xhPrice'] ?? 0;
  1467. $price = floatval($price);
  1468. $table[] = [
  1469. 'name' => $currentName,
  1470. 'num' => $num,
  1471. 'confirmNum' => '',
  1472. 'remark' => $itemRemark,
  1473. 'wxNumber' => 'shish3508',
  1474. 'unitPrice' => $unitPrice,
  1475. 'price' => $price,
  1476. ];
  1477. }
  1478. }
  1479. $shop = $this->shop;
  1480. $sjName = $shop->merchantName ?? '';
  1481. $shopName = $shop->shopName ?? '';
  1482. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1483. $a4Print = [
  1484. 'customName' => $fullCustom,
  1485. 'staffName' => $staffName,
  1486. 'seatSn' => $seatSn,
  1487. 'shortSendTimeWant' => $shortSendTimeWant,
  1488. 'table' => $table,
  1489. 'remark' => $remark,
  1490. 'fullAddress' => $fullAddress,
  1491. 'sendNum' => $sendNum,
  1492. 'sendCost' => $sendCost,
  1493. 'ysName' => $ysName,
  1494. 'packCost' => $packCost,
  1495. 'totalItemNum' => $totalItemNum,
  1496. 'totalSmallItemNum' => $totalSmallItemNum,
  1497. 'shopName' => $sjShopName . ' 销售单',
  1498. ];
  1499. $info['printData'] = $a4Print;
  1500. //常规模板
  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,"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}}]}';
  1502. if (getenv('YII_ENV') == 'production') {
  1503. //花大苪模板
  1504. if (in_array($this->mainId, [8164])) {
  1505. $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":{}}]}';
  1506. }
  1507. } else {
  1508. //测试模板
  1509. if (in_array($this->mainId, [644])) {
  1510. $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":{}}]}';
  1511. }
  1512. }
  1513. $info['template'] = $template;
  1514. //是否有云打印判断
  1515. $hasCloudPrint = 0;
  1516. $shopExt = $this->shopExt;
  1517. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1518. $hasCloudPrint = 1;
  1519. }
  1520. $info['hasCloudPrint'] = $hasCloudPrint;
  1521. $purchaseId = $info['purchaseId'] ?? 0;
  1522. $cg = PurchaseClass::getById($purchaseId);
  1523. $info['cgInfo'] = $cg;
  1524. //店长信息
  1525. $mainId = $cg['mainId'] ?? 0;
  1526. $superInfo = ShopAdminClass::getManager($mainId);
  1527. $info['customSuper'] = $superInfo;
  1528. util::success($info);
  1529. }
  1530. //获取订单信息 ssh 20240102
  1531. public function actionGetInfoByOrderSn()
  1532. {
  1533. $get = Yii::$app->request->get();
  1534. $orderSn = $get['orderSn'] ?? '';
  1535. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  1536. if (empty($info)) {
  1537. util::fail('没有找到订单');
  1538. }
  1539. if ($info->mainId != $this->mainId) {
  1540. util::fail('不是你的订单哦');
  1541. }
  1542. util::success(['info' => $info]);
  1543. }
  1544. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1545. public function actionInfo()
  1546. {
  1547. $get = Yii::$app->request->get();
  1548. $id = $get['id'] ?? 0;
  1549. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1550. if (empty($info)) {
  1551. util::fail('没有找到订单');
  1552. }
  1553. //是否有云打印判断
  1554. $hasCloudPrint = 0;
  1555. $shopExt = $this->shopExt;
  1556. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1557. $hasCloudPrint = 1;
  1558. }
  1559. $info['hasCloudPrint'] = $hasCloudPrint;
  1560. $purchaseId = $info['purchaseId'] ?? 0;
  1561. $cg = PurchaseClass::getById($purchaseId);
  1562. $info['cgInfo'] = $cg;
  1563. //店长信息
  1564. $mainId = $cg['mainId'] ?? 0;
  1565. $superInfo = ShopAdminClass::getManager($mainId);
  1566. $info['customSuper'] = $superInfo;
  1567. util::success($info);
  1568. }
  1569. //自取免发货流程处理 ssh 2021.1.22
  1570. public function actionWithoutSend()
  1571. {
  1572. util::complete();
  1573. }
  1574. //本店送 ssh 2021.1.24
  1575. public function actionSelfSend()
  1576. {
  1577. $get = Yii::$app->request->get();
  1578. $id = isset($get['id']) ? $get['id'] : 0;
  1579. $info = OrderClass::getById($id, true);
  1580. OrderClass::valid($info->attributes, $this->shopId);
  1581. $connection = Yii::$app->db;
  1582. $transaction = $connection->beginTransaction();
  1583. try {
  1584. OrderClass::selfSend($info);
  1585. $transaction->commit();
  1586. } catch (\Exception $exception) {
  1587. $transaction->rollBack();
  1588. Yii::info("本店送操作报错:" . $exception->getMessage());
  1589. util::fail('操作失败');
  1590. }
  1591. util::complete();
  1592. }
  1593. //运费计算 ssh 2021.1.24
  1594. public function actionFreight()
  1595. {
  1596. //2021.3.28 接入达达
  1597. $get = Yii::$app->request->get();
  1598. $post = Yii::$app->request->post();
  1599. if (empty($get)) {
  1600. $get = $post;
  1601. }
  1602. $orderId = $get['id'] ?? 0; //订单ID
  1603. $customId = $get['customId'] ?? 0;
  1604. if (empty($orderId)) {
  1605. //自定义运费
  1606. //freight::getCost();
  1607. if (empty($customId)) {
  1608. util::fail("请选择客户");
  1609. }
  1610. $customInfo = CustomClass::getById($customId);
  1611. if (empty($customInfo)) {
  1612. util::fail('没有找到客户');
  1613. }
  1614. $shop = $this->shop;
  1615. //花材信息
  1616. $productJson = $get['product'] ?? '';
  1617. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1618. if (empty($productJson)) {
  1619. util::fail('请选择花材');
  1620. }
  1621. $productList = json_decode($productJson, true);
  1622. if (empty($productList)) {
  1623. util::fail('请选择花材');
  1624. }
  1625. $productList = ProductClass::mergeItemInfo($productList);
  1626. $weight = 0;
  1627. $price = 0;
  1628. $productData = ProductClass::getProductMapData($productList);
  1629. $bigNum = 0;
  1630. foreach ($productList as $key => $val) {
  1631. $productId = $val['productId'];
  1632. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1633. $bigNum += $val['bigNum'];
  1634. $weight = bcadd($w, $weight, 2);
  1635. $ratio = $productData[$productId]['ratio'] ?? 0;
  1636. //大小数量合并多少扎
  1637. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1638. //售卖价格
  1639. $itemPrice = $productData[$productId]['price'] ?? 0;
  1640. //合计价格
  1641. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1642. }
  1643. //没有经纬度的客户运费直接返回空 ssh 20210612
  1644. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1645. util::success(['sedCost' => '']);
  1646. }
  1647. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1648. util::success(['sedCost' => $cost]);
  1649. }
  1650. $province = $get['province'] ?? '';
  1651. $city = $get['city'] ?? '';
  1652. $address = $get['address'] ?? '';
  1653. $floor = $get['floor'] ?? '';
  1654. $customName = $get['customName'] ?? '';
  1655. $customMobile = $get['customMobile'] ?? '';
  1656. $fullAddress = $province . $city . $address . $floor;
  1657. $sendTime = $get['sendTime'] ?? '';
  1658. $lat = $get['lat'] ?? '';
  1659. $lng = $get['long'] ?? '';
  1660. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1661. util::fail('请填写客户地址');
  1662. }
  1663. ini_set('date.timezone', 'Asia/Shanghai');
  1664. if (!empty($sendTime)) {
  1665. //配送时间不为空
  1666. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1667. $sendTimeInt = strtotime($sendTime);
  1668. $now = time();
  1669. $diff = $sendTimeInt - $now;
  1670. //因服务器写入时间,改为至少提前6分钟
  1671. if ($diff <= 360) {
  1672. util::fail('配送时间至少提前6分钟');
  1673. }
  1674. } else {
  1675. //默认立即发送
  1676. $sendTime = 0;
  1677. }
  1678. //更新订单表
  1679. $info = OrderService::getOrderInfo($orderId);
  1680. OrderClass::valid($info, $this->shopId);
  1681. if ($sendTime) {
  1682. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1683. } else {
  1684. $sendTime = '0000-00-00 00:00:00';
  1685. }
  1686. $expressAddInfo = [
  1687. 'customName' => $customName,
  1688. 'customMobile' => $customMobile,
  1689. 'province' => $province,
  1690. 'city' => $city,
  1691. 'address' => $address,
  1692. 'floor' => $floor,
  1693. 'lat' => $lat,
  1694. 'long' => $lng,
  1695. 'sendTime' => $sendTime,
  1696. ];
  1697. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  1698. //计算运费
  1699. $info['province'] = $province;
  1700. $info['city'] = $city;
  1701. $info['address'] = $address;
  1702. $info['floor'] = $floor;
  1703. $info['fullAddress'] = $fullAddress;
  1704. $info['lat'] = $lat;
  1705. $info['long'] = $lng;
  1706. $info['sendTime'] = $expressAddInfo['sendTime'];
  1707. $res = DadaExpressServices::queryDeliverFee($info);
  1708. util::success(['sedCost' => $res['fee']]);
  1709. }
  1710. //发快递和第三方配送 ssh 2021.1.24
  1711. public function actionThirdSend()
  1712. {
  1713. $get = Yii::$app->request->get();
  1714. $id = isset($get['id']) ? $get['id'] : 0;
  1715. $info = OrderService::getById($id, true);
  1716. OrderClass::valid($info->attributes, $this->shopId);
  1717. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  1718. util::fail('请填写客户地址');
  1719. }
  1720. $connection = Yii::$app->db;
  1721. $transaction = $connection->beginTransaction();
  1722. try {
  1723. $respond = OrderClass::thirdSend($info, $get);
  1724. $transaction->commit();
  1725. util::success($respond);
  1726. } catch (\Exception $exception) {
  1727. $transaction->rollBack();
  1728. Yii::info("发快递操作报错:" . $exception->getMessage());
  1729. util::fail('操作失败' . $exception->getMessage());
  1730. }
  1731. }
  1732. //确认送达 ssh 2021.1.24
  1733. public function actionReach()
  1734. {
  1735. $get = Yii::$app->request->get();
  1736. $id = isset($get['id']) ? $get['id'] : 0;
  1737. $info = OrderClass::getById($id, true);
  1738. OrderClass::valid($info->attributes, $this->shopId);
  1739. $connection = Yii::$app->db;
  1740. $transaction = $connection->beginTransaction();
  1741. try {
  1742. OrderService::reach($info);
  1743. $transaction->commit();
  1744. } catch (\Exception $exception) {
  1745. $transaction->rollBack();
  1746. Yii::info("送达操作报错:" . $exception->getMessage());
  1747. util::fail('操作失败');
  1748. }
  1749. util::complete();
  1750. }
  1751. //下单要用到的相关信息 ssh 2019.12.6
  1752. public function actionOrderRelate()
  1753. {
  1754. $regionTree = RegionService::tree();
  1755. $shop = $this->shop->attributes;
  1756. $freight = ['first' => 5, 'add' => 2];
  1757. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1758. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1759. util::success($out);
  1760. }
  1761. //客户欠款的订单 ssh 2021.2.4
  1762. public function actionDebtList()
  1763. {
  1764. $get = Yii::$app->request->get();
  1765. $id = $get['id'] ?? 0;
  1766. $info = CustomClass::getCustom($id);
  1767. CustomClass::valid($info, $this->shopId);
  1768. $where = ['customId' => $id, 'debt' => 1];
  1769. $searchTime = $get['searchTime'] ?? '';
  1770. if (!empty($searchTime)) {
  1771. $startTime = $get['startTime'] ?? '';
  1772. $endTime = $get['endTime'] ?? '';
  1773. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1774. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1775. }
  1776. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'payTime']);
  1777. $result = ['customInfo' => $info, 'list' => $list];
  1778. util::success($result);
  1779. }
  1780. //更新打印次数
  1781. public function actionAddPrintNum()
  1782. {
  1783. $id = Yii::$app->request->get('id', 0);
  1784. $order = OrderClass::getById($id, true);
  1785. OrderClass::valid($order, $this->shopId);
  1786. $order->printNum += 1;
  1787. $order->save();
  1788. util::complete();
  1789. }
  1790. //打印订单 ssh 20210714
  1791. public function actionCloudPrintOrder()
  1792. {
  1793. $get = Yii::$app->request->get();
  1794. $id = $get['id'] ?? 0;
  1795. $showPrice = $get['showPrice'] ?? 1;
  1796. $order = OrderClass::getById($id, true);
  1797. OrderClass::valid($order, $this->shopId);
  1798. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  1799. util::fail('订单还没有付款');
  1800. }
  1801. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  1802. util::fail('订单已取消');
  1803. }
  1804. $ext = $this->shopExt;
  1805. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  1806. util::success(['hasNoPrint' => 1]);
  1807. }
  1808. OrderClass::onlinePrint($order, $showPrice);
  1809. $order->printNum += 1;
  1810. $order->save();
  1811. util::complete();
  1812. }
  1813. //订单确认完成 ssh 20210809
  1814. public function actionConfirmFinish()
  1815. {
  1816. $payWay = Yii::$app->request->get('payWay', -1);
  1817. $id = Yii::$app->request->get('id', 0);
  1818. $clearType = Yii::$app->request->get('clearType', 0);
  1819. $connection = Yii::$app->db;
  1820. $transaction = $connection->beginTransaction();
  1821. try {
  1822. $order = OrderClass::getById($id, true);
  1823. OrderClass::valid($order, $this->shopId);
  1824. $purchaseId = $order->purchaseId ?? 0;
  1825. $purchase = PurchaseClass::getById($purchaseId, true);
  1826. if (empty($purchase)) {
  1827. util::fail('没有采购信息');
  1828. }
  1829. if ($clearType == 1) {
  1830. //欠款
  1831. $payWay = dict::getDict('payWay', 'debtPay');
  1832. } elseif ($clearType == 2) {
  1833. //已收款
  1834. if ($payWay == -1) {
  1835. util::fail('请选择收款方式');
  1836. }
  1837. $shopAdmin = $this->shopAdmin;
  1838. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1839. util::fail('超管才能发起已收款');
  1840. }
  1841. } else {
  1842. util::fail('请选择结算方式');
  1843. }
  1844. //不需要打印
  1845. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  1846. $order->save();
  1847. //支付
  1848. PurchaseService::payAfter($purchase, $payWay);
  1849. OrderService::payAfter($order, $payWay);
  1850. //自己送
  1851. $info = OrderClass::getById($id, true);
  1852. OrderClass::selfSend($info);
  1853. //确认送达,并且不需要微信通知
  1854. Yii::$app->params['noNeedWxNotice'] = 1;
  1855. $info = OrderClass::getById($id, true);
  1856. OrderService::reach($info);
  1857. $transaction->commit();
  1858. util::complete('操作成功');
  1859. } catch (\Exception $exception) {
  1860. $transaction->rollBack();
  1861. Yii::info("确认完成订单报错:" . $exception->getMessage());
  1862. util::fail('操作失败');
  1863. }
  1864. }
  1865. //取消订单 ssh 20220110
  1866. public function actionCancel()
  1867. {
  1868. $shopAdmin = $this->shopAdmin;
  1869. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1870. util::fail('超管才能取消订单');
  1871. }
  1872. $id = Yii::$app->request->get('id');
  1873. $order = OrderClass::getById($id, true);
  1874. if ($order->orderType == 2) {
  1875. util::fail('客户下单,不能主动取消');
  1876. }
  1877. OrderClass::valid($order, $this->shopId);
  1878. OrderService::expire($order, true);
  1879. util::complete('已取消');
  1880. }
  1881. //获取收款语音播报地址 ssh 20211231
  1882. public function actionGetPayVoice()
  1883. {
  1884. $id = Yii::$app->request->get('id');
  1885. $order = OrderClass::getById($id, true);
  1886. $payWay = $order->payWay ?? 0;
  1887. $money = floatval($order->actPrice);
  1888. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  1889. $msg = $payment . '收款' . $money . '元';
  1890. $audio = baiduAip::transfer($msg, 4, 0);
  1891. //上传到oss
  1892. $file = time() . rand(10000, 999999) . '.mp3';
  1893. $filePath = 'tmp/arrival/money/' . $file;
  1894. oss::uploadTmpAudio($filePath, $audio);
  1895. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  1896. util::success(['url' => $url]);
  1897. }
  1898. //修改备注
  1899. public function actionModifyRemark()
  1900. {
  1901. $post = Yii::$app->request->post();
  1902. $id = $post['id'] ?? 0;
  1903. $remark = $post['remark'] ?? '';
  1904. $order = OrderClass::getById($id, true);
  1905. if (empty($order)) {
  1906. util::fail('没有找到订单');
  1907. }
  1908. if ($order->mainId != $this->mainId) {
  1909. util::fail('不是你的订单');
  1910. }
  1911. $cgId = $order->purchaseId ?? 0;
  1912. $cg = PurchaseClass::getById($cgId, true);
  1913. if (empty($cg)) {
  1914. util::fail('采购单没有找到');
  1915. }
  1916. $order->remark = $remark;
  1917. $order->save();
  1918. $cg->remark = $remark;
  1919. $cg->save();
  1920. util::complete('修改成功');
  1921. }
  1922. //修改订单的确认时间 ssh 20240511
  1923. public function actionModifyOrderConfirmTime()
  1924. {
  1925. $get = Yii::$app->request->get();
  1926. $id = $get['id'] ?? 0;
  1927. $date = $get['date'] ?? '';
  1928. if (empty($date)) {
  1929. util::fail('请选择日期');
  1930. }
  1931. $order = OrderClass::getById($id, true);
  1932. if (empty($order)) {
  1933. util::fail('没有找到订单');
  1934. }
  1935. if ($order->mainId != $this->mainId) {
  1936. util::fail('不是你的订单');
  1937. }
  1938. if ($order->payStatus == 0) {
  1939. util::fail('没有确认的订单');
  1940. }
  1941. $mainId = $this->mainId;
  1942. //超管或者约定的人可以修改日期
  1943. if (getenv('YII_ENV') == 'production') {
  1944. if (in_array($mainId, [23390])) {
  1945. if (!in_array($this->adminId, [24586, 23960])) {
  1946. util::fail('你不能修改哦');
  1947. }
  1948. }
  1949. } else {
  1950. if (in_array($mainId, [644])) {
  1951. if (!in_array($this->adminId, [919])) {
  1952. }
  1953. }
  1954. }
  1955. $payTime = $order->payTime;
  1956. $time = strtotime($payTime);
  1957. $after = date("H:i:s", $time);
  1958. $new = $date . ' ' . $after;
  1959. $cgId = $order->purchaseId ?? 0;
  1960. $cg = PurchaseClass::getById($cgId, true);
  1961. if (empty($cg)) {
  1962. util::fail('没有找到订单信息');
  1963. }
  1964. if (strtotime($new) > time()) {
  1965. util::fail('不能修改成未来时间');
  1966. }
  1967. $order->payTime = $new;
  1968. $order->save();
  1969. $cg->payTime = $new;
  1970. $cg->save();
  1971. util::complete('修改成功');
  1972. }
  1973. //应收款统计 ssh 20240528
  1974. public function actionAccountList()
  1975. {
  1976. $get = Yii::$app->request->get();
  1977. $mainId = $this->mainId;
  1978. $export = $get['export'] ?? 0;
  1979. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  1980. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  1981. $startTime = $get['startTime'] ?? '';
  1982. $endTime = $get['endTime'] ?? '';
  1983. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  1984. $start = $period['startTime'];
  1985. $end = $period['endTime'];
  1986. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  1987. $currentStartDate = date('Y-m-d', strtotime($start));
  1988. $currentEndDate = date('Y-m-d', strtotime($end));
  1989. $currentStartTime = $currentStartDate . ' 00:00:00';
  1990. $currentEndTime = $currentEndDate . ' 23:59:59';
  1991. $where = ['mainId' => $mainId];
  1992. if ($debt > -1) {
  1993. $where['debt'] = $debt;
  1994. }
  1995. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  1996. $orderList = OrderClass::getAllByCondition($where, null, '*');
  1997. $list = [];
  1998. $totalAmount = 0;
  1999. if (!empty($orderList)) {
  2000. foreach ($orderList as $orderInfo) {
  2001. $actPrice = $orderInfo['actPrice'] ?? 0;
  2002. $customId = $orderInfo['customId'] ?? 0;
  2003. $status = $orderInfo['status'] ?? 0;
  2004. $book = $orderInfo['book'] ?? 0;
  2005. if ($status == 1 || $status == 5) {
  2006. continue;
  2007. }
  2008. if ($book == 1 && $status == 2) {
  2009. continue;
  2010. }
  2011. if (isset($list[$customId])) {
  2012. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  2013. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2014. } else {
  2015. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2016. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  2017. }
  2018. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  2019. }
  2020. $list = array_values($list);
  2021. }
  2022. if ($export == 1) {
  2023. if (empty($list)) {
  2024. util::fail('没有数据需要导出');
  2025. }
  2026. ini_set('memory_limit', '2045M');
  2027. set_time_limit(0);
  2028. OrderClass::exportAccountList($list, $mainId);
  2029. util::stop();
  2030. }
  2031. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  2032. }
  2033. //应收款统计 ssh 20240528
  2034. public function actionPastList()
  2035. {
  2036. $get = Yii::$app->request->get();
  2037. $export = $get['export'] ?? 0;
  2038. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2039. $startTime = $get['startTime'] ?? '';
  2040. $endTime = $get['endTime'] ?? '';
  2041. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2042. $end = $period['endTime'];
  2043. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  2044. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end), 86400));
  2045. $totalAmount = 0;
  2046. if (!empty($customList)) {
  2047. foreach ($customList as $key => $custom) {
  2048. $customId = $custom['id'] ?? 0;
  2049. $change = CustomDebtChangeClass::getByCondition(['customId' => $customId, 'addTime<' => $currentDate], true, 'addTime DESC');
  2050. $amount = $change->balance ?? 0;
  2051. $totalAmount = bcadd($totalAmount, $amount, 2);
  2052. $customList[$key]['currentDebAmount'] = $amount;
  2053. }
  2054. $customList = array_values($customList);
  2055. }
  2056. if ($export == 1) {
  2057. $mainId = $this->mainId;
  2058. if (empty($customList)) {
  2059. util::fail('没有数据需要导出');
  2060. }
  2061. ini_set('memory_limit', '2045M');
  2062. set_time_limit(0);
  2063. OrderClass::exportPastList($customList, $mainId);
  2064. util::stop();
  2065. }
  2066. util::success(['list' => $customList, 'totalAmount' => $totalAmount]);
  2067. }
  2068. //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
  2069. public function actionYj()
  2070. {
  2071. $get = Yii::$app->request->get();
  2072. $mainId = $this->mainId;
  2073. $export = $get['export'] ?? 0;
  2074. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2075. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2076. $startTime = $get['startTime'] ?? '';
  2077. $endTime = $get['endTime'] ?? '';
  2078. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2079. $start = $period['startTime'];
  2080. $end = $period['endTime'];
  2081. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
  2082. $currentStartDate = date('Y-m-d', strtotime($start));
  2083. $currentEndDate = date('Y-m-d', strtotime($end));
  2084. $currentStartTime = $currentStartDate . ' 00:00:00';
  2085. $currentEndTime = $currentEndDate . ' 23:59:59';
  2086. $where = ['mainId' => $mainId];
  2087. if ($debt > -1) {
  2088. $where['debt'] = $debt;
  2089. }
  2090. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2091. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2092. $list = [];
  2093. $totalActPrice = 0;
  2094. $totalOrderPrice = 0;
  2095. $totalCarton = 0;
  2096. $totalPack = 0;
  2097. $totalFreight = 0;
  2098. $totalTkPrice = 0;
  2099. //增加项
  2100. $totalOnlyTkPrice = 0;
  2101. $totalNum = 0;
  2102. if (!empty($orderList)) {
  2103. foreach ($orderList as $orderInfo) {
  2104. $actPrice = $orderInfo['actPrice'] ?? 0;
  2105. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  2106. $customId = $orderInfo['customId'] ?? 0;
  2107. $status = $orderInfo['status'] ?? 0;
  2108. $book = $orderInfo['book'] ?? 0;
  2109. $orderSn = $orderInfo['orderSn'] ?? '';
  2110. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  2111. if ($status == 1 || $status == 5) {
  2112. continue;
  2113. }
  2114. if ($book == 1 && $status == 2) {
  2115. continue;
  2116. }
  2117. if ($actPrice <= 0) {
  2118. //全部已经售后
  2119. continue;
  2120. }
  2121. $carton = 0;
  2122. $pack = 0;
  2123. $freight = 0;
  2124. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  2125. if (!empty($orderItemList)) {
  2126. foreach ($orderItemList as $orderItem) {
  2127. $num = $orderItem['xhNum'] ?? 0;
  2128. $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
  2129. $refundNum = $orderItem['refundNum'] ?? 0;
  2130. $classId = $orderItem['classId'] ?? 0;
  2131. if (getenv('YII_ENV') == 'production') {
  2132. if ($mainId == 23390) {
  2133. $remainNum = bcsub($num, $refundNum);
  2134. $amount = bcmul($remainNum, $unitPrice, 2);
  2135. if ($classId == 72106) {
  2136. $carton = bcadd($carton, $amount, 2);
  2137. }
  2138. if ($classId == 72108) {
  2139. $pack = bcadd($pack, $amount, 2);
  2140. }
  2141. if ($classId == 73118) {
  2142. $freight = bcadd($freight, $amount, 2);
  2143. }
  2144. }
  2145. }
  2146. }
  2147. }
  2148. //增加项
  2149. if ($tkPrice > 0) {
  2150. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  2151. if (!empty($refundList)) {
  2152. foreach ($refundList as $refundInfo) {
  2153. if ($refundInfo->status == 1) {
  2154. if ($refundInfo->refundType == 2) {
  2155. $refundPrice = $refundInfo->refundPrice ?? 0;
  2156. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  2157. }
  2158. }
  2159. }
  2160. }
  2161. }
  2162. $totalCarton = bcadd($totalCarton, $carton, 2);
  2163. $totalPack = bcadd($totalPack, $pack, 2);
  2164. $totalFreight = bcadd($totalFreight, $freight, 2);
  2165. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  2166. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  2167. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  2168. $totalNum++;
  2169. if (isset($list[$customId])) {
  2170. $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
  2171. $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
  2172. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2173. $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton, 2);
  2174. $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $pack, 2);
  2175. $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $freight, 2);
  2176. $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice, 2);
  2177. } else {
  2178. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2179. $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
  2180. $list[$customId] = [
  2181. 'id' => $customId,
  2182. 'name' => $name,
  2183. 'mobile' => $mobile,
  2184. 'orderPrice' => $orderPrice,
  2185. 'actPrice' => $actPrice,
  2186. 'num' => 1,
  2187. 'carton' => $carton,
  2188. 'pack' => $pack,
  2189. 'freight' => $freight,
  2190. 'tkPrice' => $tkPrice,
  2191. ];
  2192. }
  2193. }
  2194. foreach ($customList as $key => $custom) {
  2195. $customId = $custom['id'] ?? 0;
  2196. if (isset($list[$customId]) == false) {
  2197. $list[$customId] = [
  2198. 'id' => $customId,
  2199. 'name' => $custom['name'],
  2200. 'mobile' => $custom['mobile'],
  2201. 'actPrice' => 0,
  2202. 'num' => 0,
  2203. 'carton' => 0,
  2204. 'pack' => 0,
  2205. 'freight' => 0,
  2206. 'tkPrice' => 0,
  2207. 'orderPrice' => 0,
  2208. ];
  2209. }
  2210. }
  2211. $list = array_values($list);
  2212. }
  2213. if ($export == 1) {
  2214. if (empty($list)) {
  2215. util::fail('没有数据需要导出');
  2216. }
  2217. ini_set('memory_limit', '2045M');
  2218. set_time_limit(0);
  2219. OrderClass::exportYj($list, $mainId);
  2220. util::stop();
  2221. }
  2222. util::success([
  2223. 'list' => $list,
  2224. 'totalActPrice' => $totalActPrice,
  2225. 'totalOrderPrice' => $totalOrderPrice,
  2226. 'totalCarton' => $totalCarton,
  2227. 'totalNum' => $totalNum,
  2228. 'totalPack' => $totalPack,
  2229. 'totalFreight' => $totalFreight,
  2230. 'totalTkPrice' => $totalTkPrice,
  2231. //增加项
  2232. 'totalOnlyTkPrice' => $totalOnlyTkPrice,
  2233. ]);
  2234. }
  2235. }