OrderController.php 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\common\classes\GhsNotifyClass;
  4. use biz\common\classes\HdNotifyClass;
  5. use biz\shop\classes\ShopExtClass;
  6. use bizGhs\custom\classes\CustomDebtChangeClass;
  7. use bizGhs\express\classes\GhsDeliveryOrderClass;
  8. use bizGhs\express\services\DadaExpressServices;
  9. use bizGhs\ghs\classes\GhsClass;
  10. use bizGhs\order\classes\OrderItemClass;
  11. use bizGhs\order\classes\RefundOrderClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use bizHd\purchase\classes\PurchaseItemClass;
  14. use bizHd\purchase\services\PurchaseService;
  15. use bizHd\wx\classes\WxOpenClass;
  16. use bizGhs\custom\classes\CustomClass;
  17. use bizGhs\order\classes\OrderClass;
  18. use bizGhs\order\services\OrderService;
  19. use bizHd\saas\services\RegionService;
  20. use bizGhs\product\classes\ProductClass;
  21. use common\components\baiduAip;
  22. use common\components\dict;
  23. use common\components\dateUtil;
  24. use common\components\dirUtil;
  25. use common\components\freight;
  26. use common\components\httpUtil;
  27. use common\components\noticeUtil;
  28. use common\components\orderSn;
  29. use common\components\oss;
  30. use common\components\payUtil;
  31. use common\components\qrCodeUtil;
  32. use common\components\stringUtil;
  33. use Yii;
  34. use common\components\util;
  35. use biz\shop\classes\ShopAdminClass;
  36. use biz\shop\classes\ShopClass;
  37. use common\components\lakala\Lakala;
  38. use ghs\models\order\CreateOrderForm;
  39. class OrderController extends BaseController
  40. {
  41. public $guestAccess = ['create-order', 'order-relate', 'fast-pay', 'info'];
  42. //打印物流列表 ssh 20250712
  43. public function actionPrintWlList()
  44. {
  45. $get = Yii::$app->request->get();
  46. $begin = $get['begin'] ?? 1;
  47. $hour = $get['hour'] ?? 0;
  48. if ($hour > 24 || $hour < 0) {
  49. util::fail('必须0到24点');
  50. }
  51. if ($begin == 0) {
  52. $date = date('Y-m-d', strtotime('-1 day'));
  53. } else {
  54. $date = date('Y-m-d');
  55. }
  56. $beginGroup = $date . " {$hour}:00:00";
  57. $newTime = strtotime($beginGroup);
  58. $beginTime = date('Y-m-d H:i:s', $newTime);
  59. $endTime = date("Y-m-d H:i:s");
  60. $shop = $this->shop;
  61. OrderClass::printMyWlList($shop, $beginTime, $endTime);
  62. util::complete('打印成功');
  63. }
  64. //修改平账标识状态 ssh 20240405
  65. public function actionModifyClearSign()
  66. {
  67. $get = Yii::$app->request->get();
  68. $id = $get['id'] ?? '';
  69. $order = OrderClass::getById($id, true);
  70. if (empty($order)) {
  71. util::fail('没有找到订单');
  72. }
  73. if ($order->mainId != $this->mainId) {
  74. util::fail('不是你的订单');
  75. }
  76. if (!in_array($order->status, [3, 4])) {
  77. util::fail('订单没有发货');
  78. }
  79. if ($order->clearSign == 1) {
  80. util::fail('不需要重复操作');
  81. }
  82. $connection = Yii::$app->db;
  83. $transaction = $connection->beginTransaction();
  84. try {
  85. $order->clearSign = 1;
  86. $order->save();
  87. $cgId = $order->purchaseId;
  88. $cg = PurchaseClass::getById($cgId, true);
  89. if (empty($cg)) {
  90. util::fail('没有找到采购信息');
  91. }
  92. $cg->clearSign = 1;
  93. $cg->save();
  94. $transaction->commit();
  95. util::complete();
  96. } catch (\Exception $e) {
  97. $transaction->rollBack();
  98. Yii::error("操作失败原因:" . $e->getMessage());
  99. util::fail('操作失败');
  100. }
  101. }
  102. //下载图片版订单 ssh 20240321
  103. public function actionDown()
  104. {
  105. $get = Yii::$app->request->get();
  106. $id = $get['id'] ?? '';
  107. $all = $get['all'] ?? 0;
  108. $order = OrderClass::getById($id, true);
  109. if (empty($order)) {
  110. util::fail('没有找到订单');
  111. }
  112. if ($order->mainId != $this->mainId) {
  113. util::fail('不是你的订单');
  114. }
  115. $customName = $order->customName ?? '';
  116. $date = date("Ymd", strtotime($order->addTime));
  117. $orderSn = $order->orderSn ?? '';
  118. $name = $customName . '_' . $date . '_' . $orderSn;
  119. $shop = $this->shop;
  120. $staff = $this->shopAdmin;
  121. $respond = OrderClass::createImgOrder($order, $shop, $staff, $all);
  122. $imgUrl = $respond['imgFile'] ?? '';
  123. $file = fopen($imgUrl, "rb");
  124. Header("Content-type: application/octet-stream ");
  125. Header("Accept-Ranges: bytes ");
  126. Header("Content-Disposition: attachment;filename={$name}.png");
  127. $contents = "";
  128. while (!feof($file)) {
  129. $contents .= fread($file, 8192);
  130. }
  131. echo $contents;
  132. fclose($file);
  133. }
  134. //确认送达
  135. public function actionConfirmReach()
  136. {
  137. $get = Yii::$app->request->get();
  138. $id = $get['id'] ?? '';
  139. $order = OrderClass::getById($id, true);
  140. if (empty($order)) {
  141. util::fail('没有找到订单');
  142. }
  143. if ($order->mainId != $this->mainId) {
  144. util::fail('不是你的订单');
  145. }
  146. if ($order->status == 1) {
  147. util::fail('订单待付款');
  148. }
  149. if ($order->status == 4) {
  150. util::fail('订单已完成');
  151. }
  152. if ($order->status == 5) {
  153. util::fail('订单已取消');
  154. }
  155. if (!in_array($order->sendStatus, [-1, -4, -2])) {
  156. util::fail('已经叫跑腿了');
  157. }
  158. $connection = Yii::$app->db;
  159. $transaction = $connection->beginTransaction();
  160. try {
  161. $staff = $this->shopAdmin;
  162. $staffId = $staff->id ?? 0;
  163. $staffName = $staff->name ?? '';
  164. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  165. OrderClass::confirmReach($order, $params);
  166. $transaction->commit();
  167. util::complete('操作成功');
  168. } catch (\Exception $e) {
  169. $transaction->rollBack();
  170. Yii::error("操作失败原因:" . $e->getMessage());
  171. util::fail('确认失败');
  172. }
  173. }
  174. public function actionAllFh()
  175. {
  176. $post = Yii::$app->request->post();
  177. $ids = $post['ids'] ?? '';
  178. if (empty($ids)) {
  179. util::fail('请选择要合并发货的订单');
  180. }
  181. $arr = explode(',', $ids);
  182. if (empty($arr)) {
  183. util::fail('请选择要合并发货的订单哦');
  184. }
  185. $fhWl = $post['fhWl'] ?? '';
  186. $fhWlNo = $post['fhWlNo'] ?? '';
  187. $fhType = 0;
  188. $params = [
  189. 'fhType' => $fhType,
  190. 'fhWl' => $fhWl,
  191. 'fhWlNo' => $fhWlNo,
  192. ];
  193. $connection = Yii::$app->db;
  194. $transaction = $connection->beginTransaction();
  195. try {
  196. $all = OrderClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true);
  197. foreach ($all as $order) {
  198. if ($order->book == 1) {
  199. util::fail('有预订单,不能一起发货');
  200. }
  201. if ($order->mainId != $this->mainId) {
  202. util::fail('不是你的订单哦');
  203. }
  204. OrderClass::orderSend($order, $params, true);
  205. }
  206. $transaction->commit();
  207. util::complete();
  208. } catch (\Exception $e) {
  209. $transaction->rollBack();
  210. Yii::error("操作失败原因:" . $e->getMessage());
  211. util::fail('操作失败');
  212. }
  213. }
  214. //发货 ssh 20230613
  215. public function actionFh()
  216. {
  217. $post = Yii::$app->request->post();
  218. $id = $post['id'] ?? '';
  219. $order = OrderClass::getById($id, true);
  220. OrderClass::valid($order, $this->shopId);
  221. $staff = $this->shopAdmin;
  222. $staffId = $staff->id ?? 0;
  223. $staffName = $staff->name ?? '';
  224. $fhWl = $post['fhWl'] ?? '';
  225. $fhWlNo = $post['fhWlNo'] ?? '';
  226. $fhType = $post['fhType'] ?? '';
  227. $params = [
  228. 'fhType' => $fhType,
  229. 'fhWl' => $fhWl,
  230. 'fhWlNo' => $fhWlNo,
  231. 'staffId' => $staffId,
  232. 'staffName' => $staffName,
  233. ];
  234. if ($order->book == 1) {
  235. util::fail('预订单不能直接发货');
  236. }
  237. $connection = Yii::$app->db;
  238. $transaction = $connection->beginTransaction();
  239. try {
  240. //花店会增加路上库存
  241. OrderClass::orderSend($order, $params);
  242. $transaction->commit();
  243. util::complete();
  244. } catch (\Exception $e) {
  245. $transaction->rollBack();
  246. Yii::error("操作失败原因:" . $e->getMessage());
  247. util::fail('操作失败');
  248. }
  249. }
  250. //合并打印 ssh 20230929
  251. public function actionMergePrint()
  252. {
  253. $post = Yii::$app->request->post();
  254. $ids = $post['ids'] ?? '';
  255. if (empty($ids)) {
  256. util::fail('请选择要合并打印的订单');
  257. }
  258. $arr = explode(',', $ids);
  259. if (empty($arr)) {
  260. util::fail('请选择要合并打印的订单哦');
  261. }
  262. if (getenv('YII_ENV') == 'production') {
  263. if ($this->mainId != 10536 && $this->mainId != 50) {
  264. //util::fail('功能开发中');
  265. }
  266. } else {
  267. if ($this->mainId != 11) {
  268. //util::fail('功能开发中');
  269. }
  270. }
  271. OrderClass::mergePrintOrder($arr, $this->mainId);
  272. util::complete('打印成功');
  273. }
  274. //修改分工 ssh 20221129
  275. public function actionChangeWorker()
  276. {
  277. $post = Yii::$app->request->post();
  278. $id = $post['id'] ?? 0;
  279. $shopAdminId = $post['shopAdminId'] ?? 0;
  280. $shopAdminName = $post['shopAdminName'] ?? '';
  281. $order = OrderClass::getById($id, true);
  282. OrderClass::valid($order, $this->shopId);
  283. $preShopAdminId = $order->shopAdminId ?? 0;
  284. if (!empty($preShopAdminId)) {
  285. $shopAdmin = $this->shopAdmin;
  286. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  287. util::fail('管理员才能操作');
  288. }
  289. }
  290. $order->shopAdminId = $shopAdminId;
  291. $order->shopAdminName = $shopAdminName;
  292. $order->save();
  293. util::complete();
  294. }
  295. //预订单到货 ssh 20220321
  296. public function actionArrival()
  297. {
  298. //避免重复提交
  299. $adminId = $this->adminId;
  300. util::checkRepeatCommit($adminId, 6);
  301. $post = Yii::$app->request->post();
  302. $id = $post['id'] ?? 0;
  303. $todayBill = $post['todayBill'] ?? 1;
  304. $connection = Yii::$app->db;
  305. $transaction = $connection->beginTransaction();
  306. try {
  307. $order = OrderClass::getById($id, true);
  308. OrderClass::valid($order, $this->shopId);
  309. $post['shopAdminId'] = $this->shopAdminId;
  310. $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
  311. $shop = $this->shop;
  312. $bookSn = $shop->bookSn ?? 0;
  313. if (!empty($bookSn)) {
  314. if ($order->bookSn == $bookSn) {
  315. util::fail('预订结束了才能确认');
  316. }
  317. }
  318. OrderService::arrival($order, $post);
  319. if ($todayBill == 0) {
  320. $lastTime = time() - 86400;
  321. $payTime = date("Y-m-d H:i:s", $lastTime);
  322. $order->payTime = $payTime;
  323. $order->save();
  324. $purchaseId = $order->purchaseId ?? 0;
  325. $cg = PurchaseClass::getById($purchaseId, true);
  326. if (!empty($cg)) {
  327. $cg->payTime = $payTime;
  328. $cg->save();
  329. }
  330. }
  331. $transaction->commit();
  332. util::success($order);
  333. } catch (\Exception $e) {
  334. $transaction->rollBack();
  335. Yii::error("操作失败原因:" . $e->getMessage());
  336. util::fail('操作失败');
  337. }
  338. }
  339. //到货获取订单详情 ssh 20220323
  340. public function actionArrivalDetail()
  341. {
  342. $get = Yii::$app->request->get();
  343. $id = $get['id'] ?? 0;
  344. $info = OrderClass::getById($id);
  345. OrderClass::valid($info, $this->shopId);
  346. $showItemData = OrderClass::getOriginalShowItem(true, $info);
  347. $itemList = $showItemData['list'] ?? [];
  348. $info['product'] = $itemList;
  349. $kiloFee = $this->shop->kiloFee ?? 0;
  350. $miniKilo = $this->shop->miniKilo ?? 0;
  351. $info['kiloFee'] = $kiloFee;
  352. $info['miniKilo'] = $miniKilo;
  353. util::success($info);
  354. }
  355. //支付宝扫码支付 ssh 20210103
  356. public function actionScanPayCheck()
  357. {
  358. $get = Yii::$app->request->get();
  359. $id = isset($get['id']) ? $get['id'] : 0;
  360. $order = OrderClass::getById($id, true);
  361. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
  362. util::success(['returnStatus' => 'SUCCESS']);
  363. }
  364. $deadline = $order->deadline ?? '';
  365. $deadTime = strtotime($deadline);
  366. $current = time();
  367. $diff = bcsub($deadTime, $current);
  368. if ($diff <= 60) {
  369. util::success(['returnStatus' => 'EXPIRE']);
  370. }
  371. util::success(['returnStatus' => 'FAILURE']);
  372. }
  373. //微信和支付宝扫码支付 ssh 20210103
  374. public function actionScanPay()
  375. {
  376. ini_set('date.timezone', 'Asia/Shanghai');
  377. header("Content-type: text/html; charset=utf-8");
  378. $get = Yii::$app->request->get();
  379. $id = isset($get['id']) ? $get['id'] : 0;
  380. $order = OrderClass::getById($id, true);
  381. if (isset($order->status) == false || $order->status != 1) {
  382. util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
  383. }
  384. OrderClass::valid($order, $this->shopId);
  385. $cgId = $order->purchaseId ?? 0;
  386. $cg = PurchaseClass::getById($cgId, true);
  387. $orderSn = $cg->orderSn ?? '';
  388. if (empty($orderSn)) {
  389. util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
  390. }
  391. $deadline = $cg->deadline;
  392. $current = date("Y-m-d H:i:s");
  393. if ((strtotime($deadline) + 20) < strtotime($current)) {
  394. util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
  395. }
  396. $totalFee = $cg->actPrice ?? 0;
  397. $subject = '购买鲜花';
  398. $totalAmount = $totalFee;
  399. $body = "到店订单";
  400. //标记为扫码支付 和 自取订单
  401. $order->codePay = 2;
  402. $order->sendType = OrderClass::SEND_TYPE_NO;
  403. $order->save();
  404. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  405. $cg->codePay = 2;
  406. $cg->save();
  407. $shop = $this->shop;
  408. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  409. $wxPayWay = dict::getDict('payWay', 'wxPay');
  410. $aliPayWay = dict::getDict('payWay', 'alipay');
  411. $payWay = Yii::$app->request->get('payWay', $wxPayWay);
  412. if ($payWay == $wxPayWay) {
  413. if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
  414. $url = $order->wxPayUrl;
  415. } else {
  416. util::fail('暂不支持');
  417. $merchantExtend = WxOpenClass::getWxInfo();
  418. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  419. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  420. $params = [
  421. 'appid' => 'OP00002119',
  422. 'serial_no' => '018b08cfddbd',
  423. 'merchant_no' => $shop->lklSjNo,
  424. 'term_no' => $shop->lklScanTermNo,
  425. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  426. 'lklCertificatePath' => $lklCertificatePath,
  427. ];
  428. $laResource = new Lakala($params);
  429. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  430. $wxParams = [
  431. 'orderSn' => $orderSn,
  432. 'amount' => $totalFee,
  433. 'capitalType' => $currentCapitalType,
  434. 'notifyUrl' => $notifyUrl,
  435. 'subject' => $subject,
  436. 'couponId' => 0,
  437. 'wxAppId' => $merchantExtend['miniAppId'],
  438. ];
  439. $response = $laResource->driveNativeWxPay($wxParams);
  440. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  441. $msg = $response['msg'] ?? '';
  442. noticeUtil::push($msg, '15280215347');
  443. util::fail('二维码生成失败');
  444. }
  445. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  446. if (empty($url)) {
  447. util::fail('二维码生成失败..');
  448. }
  449. $order->wxPayUrl = $url;
  450. $order->save();
  451. }
  452. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  453. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  454. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  455. }
  456. if ($payWay == $aliPayWay) {
  457. if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
  458. $url = $order->aliPayUrl;
  459. } else {
  460. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  461. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  462. $params = [
  463. 'appid' => 'OP00002119',
  464. 'serial_no' => '018b08cfddbd',
  465. 'merchant_no' => $shop->lklSjNo,
  466. 'term_no' => $shop->lklScanTermNo,
  467. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  468. 'lklCertificatePath' => $lklCertificatePath,
  469. ];
  470. $laResource = new Lakala($params);
  471. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  472. $aliParams = [
  473. 'orderSn' => $orderSn,
  474. 'amount' => $totalFee,
  475. 'capitalType' => $currentCapitalType,
  476. 'notifyUrl' => $notifyUrl,
  477. 'subject' => $subject,
  478. ];
  479. $response = $laResource->driveAliPay($aliParams);
  480. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  481. util::fail('二维码生成失败');
  482. }
  483. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  484. if (empty($url)) {
  485. util::fail('二维码生成失败..');
  486. }
  487. $order->aliPayUrl = $url;
  488. $order->save();
  489. }
  490. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  491. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  492. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  493. }
  494. util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
  495. }
  496. //微信和支付宝付款码支付复查 ssh 20211231
  497. public function actionCodePayCheck()
  498. {
  499. ini_set('date.timezone', 'Asia/Shanghai');
  500. header("Content-type: text/html; charset=utf-8");
  501. $get = Yii::$app->request->get();
  502. $id = isset($get['id']) ? $get['id'] : 0;
  503. util::checkRepeatCommit($id, 3);
  504. $order = OrderClass::getById($id, true);
  505. if (empty($order)) {
  506. util::success(['returnStatus' => 'SUCCESS']);
  507. }
  508. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  509. util::complete('订单已付款');
  510. }
  511. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  512. util::complete('订单已取消');
  513. }
  514. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  515. util::complete('订单不是待付款状态');
  516. }
  517. OrderClass::valid($order, $this->shopId);
  518. $cgId = $order->purchaseId ?? 0;
  519. $cg = PurchaseClass::getById($cgId, true);
  520. $orderSn = $cg->orderSn ?? '';
  521. $totalFee = $cg->actPrice ?? 0;
  522. if (empty($orderSn)) {
  523. util::complete('没有找到采购单');
  524. }
  525. $connection = Yii::$app->db;
  526. $transaction = $connection->beginTransaction();
  527. try {
  528. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  529. $shop = $this->shop;
  530. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  531. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  532. $params = [
  533. 'appid' => 'OP00002119',
  534. 'serial_no' => '018b08cfddbd',
  535. 'merchant_no' => $shop->lklSjNo,
  536. 'term_no' => $shop->lklScanTermNo,
  537. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  538. 'lklCertificatePath' => $lklCertificatePath,
  539. ];
  540. $laResource = new Lakala($params);
  541. $scanParams = ['orderSn' => $orderSn,];
  542. $response = $laResource->query($scanParams);
  543. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  544. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  545. //支付成功
  546. $transactionId = $response['resp_data']['trade_no'] ?? '';
  547. $openId = '';
  548. $aliUserId = '';
  549. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  550. $cg->codePay = 1;
  551. $cg->payOpenId = $openId;
  552. $cg->aliUserId = $aliUserId;
  553. //自取订单
  554. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  555. $cg->save();
  556. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  557. $order->codePay = 1;
  558. //自取订单
  559. $order->sendType = OrderClass::SEND_TYPE_NO;
  560. $order->save();
  561. $payWayType = dict::getDict('payWay', 'wxPay');
  562. $account_type = $response['resp_data']['account_type'] ?? '';
  563. if ($account_type == 'WECHAT') {
  564. $payWayType = dict::getDict('payWay', 'wxPay');
  565. }
  566. if ($account_type == 'ALIPAY') {
  567. $payWayType = dict::getDict('payWay', 'alipay');
  568. }
  569. $order->payWay = $payWayType;
  570. $order->save();
  571. $cg->payWay = $payWayType;
  572. $cg->save();
  573. $attach = '';
  574. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  575. $transaction->commit();
  576. $saleId = $order->id ?? 0;
  577. $order = OrderClass::getById($saleId, true);
  578. if (!empty($order)) {
  579. //解决扫码付重复打印问题
  580. $cacheKey = 'scan_pay_print_order_' . $orderSn;
  581. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  582. if (!empty($has)) {
  583. return false;
  584. }
  585. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  586. //订单生成时唤起在线打印
  587. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  588. if ($order->status != 1 && $order->status != 5) {
  589. OrderClass::onlinePrint($order);
  590. $ext = $this->shopExt;
  591. if (isset($ext->printSn) && !empty($ext->printSn)) {
  592. $order->printNum += 1;
  593. $order->save();
  594. }
  595. }
  596. }
  597. ShopExtClass::ghsGatheringReport($order);
  598. }
  599. util::success(['returnStatus' => 'SUCCESS']);
  600. } else {
  601. util::complete('未知状态..');
  602. }
  603. } else {
  604. util::complete('未知状态....');
  605. }
  606. } catch (\Exception $e) {
  607. $transaction->rollBack();
  608. noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
  609. util::fail('支付失败');
  610. }
  611. }
  612. //微信和支付宝付款码支付 ssh 2021.4.11
  613. public function actionCodePay()
  614. {
  615. ini_set('date.timezone', 'Asia/Shanghai');
  616. header("Content-type: text/html; charset=utf-8");
  617. $get = Yii::$app->request->get();
  618. $id = isset($get['id']) ? $get['id'] : 0;
  619. util::checkRepeatCommit($id, 3);
  620. $order = OrderClass::getById($id, true);
  621. if (empty($order)) {
  622. $msg = '没有找到订单';
  623. util::success(['returnStatus' => 'FAILURE'], $msg);
  624. }
  625. if ($order->status == 5) {
  626. $msg = '订单已取消';
  627. util::success(['returnStatus' => 'FAILURE'], $msg);
  628. }
  629. if ($order->status != 1) {
  630. $msg = '不是待付款订单';
  631. util::success(['returnStatus' => 'FAILURE'], $msg);
  632. }
  633. OrderClass::valid($order, $this->shopId);
  634. $cgId = $order->purchaseId ?? 0;
  635. $cg = PurchaseClass::getById($cgId, true);
  636. $orderSn = $cg->orderSn ?? '';
  637. if (empty($orderSn)) {
  638. $msg = '没有找到采购单';
  639. util::success(['returnStatus' => 'FAILURE'], $msg);
  640. }
  641. $codePayErrorKey = 'code_pay_error_' . $id;
  642. $hasFailPay = Yii::$app->redis->executeCommand('GET', [$codePayErrorKey]);
  643. //前面有付失败过,要重新生成单号
  644. if (!empty($hasFailPay)) {
  645. $oldOrderSn = $orderSn;
  646. $shopId = $cg->shopId ?? 0;
  647. $mainId = $cg->mainId ?? 0;
  648. $ghsId = $cg->ghsId ?? 0;
  649. $customId = $cg->customId ?? 0;
  650. $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'customId' => $customId];
  651. $orderSn = orderSn::getPurchaseSn($snData);
  652. $cg->orderSn = $orderSn;
  653. $cg->save();
  654. //noticeUtil::push("重新扫码,成功更换单号 {$oldOrderSn} {$orderSn}", '15280215347');
  655. PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  656. }
  657. $shop = $this->shop;
  658. $sj = $shop->merchantName;
  659. $shopName = $shop->shopName;
  660. $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
  661. //付款码
  662. $authCode = (string)$get['authCode'] ?? '';
  663. $authCode = trim($authCode);
  664. if (empty($authCode)) {
  665. $msg = '没有扫到付款码';
  666. $remind = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
  667. noticeUtil::push($remind . ' 编号001', '15280215347');
  668. util::success(['returnStatus' => 'FAILURE'], $msg);
  669. }
  670. //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
  671. $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
  672. //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
  673. $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
  674. if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
  675. $msg = '付款码错误,请使用微信或支付宝付款码';
  676. $remind = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
  677. //noticeUtil::push($remind . ' 编号002', '15280215347');
  678. util::success(['returnStatus' => 'FAILURE'], $msg);
  679. }
  680. $deadline = $cg->deadline;
  681. $current = date("Y-m-d H:i:s");
  682. if ((strtotime($deadline) + 20) < strtotime($current)) {
  683. $msg = '订单已经失效';
  684. util::success(['returnStatus' => 'FAILURE'], $msg);
  685. }
  686. $totalFee = $cg->actPrice ?? 0;
  687. $connection = Yii::$app->db;
  688. $transaction = $connection->beginTransaction();
  689. try {
  690. $subject = '购买花材 ' . $orderSn;
  691. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  692. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  693. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  694. $params = [
  695. 'appid' => 'OP00002119',
  696. 'serial_no' => '018b08cfddbd',
  697. 'merchant_no' => $shop->lklSjNo,
  698. 'term_no' => $shop->lklScanTermNo,
  699. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  700. 'lklCertificatePath' => $lklCertificatePath,
  701. ];
  702. $laResource = new Lakala($params);
  703. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  704. $scanParams = [
  705. 'orderSn' => $orderSn,
  706. 'amount' => $totalFee,
  707. 'capitalType' => $capitalType,
  708. 'notifyUrl' => $notifyUrl,
  709. 'subject' => $subject,
  710. 'authCode' => $authCode,
  711. ];
  712. $response = $laResource->scanPay($scanParams);
  713. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  714. $account_type = $response['resp_data']['account_type'] ?? '';
  715. $payWayType = dict::getDict('payWay', 'wxPay');
  716. if ($account_type == 'WECHAT') {
  717. $payWayType = dict::getDict('payWay', 'wxPay');
  718. }
  719. if ($account_type == 'ALIPAY') {
  720. $payWayType = dict::getDict('payWay', 'alipay');
  721. }
  722. $order->payWay = $payWayType;
  723. $order->save();
  724. $cg->payWay = $payWayType;
  725. $cg->save();
  726. $transactionId = $response['resp_data']['trade_no'] ?? '';
  727. $openId = '';
  728. $aliUserId = '';
  729. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  730. $cg->codePay = 1;
  731. $cg->payOpenId = $openId;
  732. $cg->aliUserId = $aliUserId;
  733. $cg->save();
  734. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  735. $order->codePay = 1;
  736. $order->save();
  737. $attach = '';
  738. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  739. $transaction->commit();
  740. $saleId = $order->id ?? 0;
  741. $order = OrderClass::getById($saleId, true);
  742. if (!empty($order)) {
  743. //解决扫码付重复打印问题
  744. $cacheKey = 'scan_pay_print_order_' . $orderSn;
  745. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  746. if (!empty($has)) {
  747. return false;
  748. }
  749. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  750. //订单生成时唤起在线打印
  751. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  752. if ($order->status != 1 && $order->status != 5) {
  753. OrderClass::onlinePrint($order);
  754. $ext = $this->shopExt;
  755. if (isset($ext->printSn) && !empty($ext->printSn)) {
  756. $order->printNum += 1;
  757. $order->save();
  758. }
  759. }
  760. }
  761. ShopExtClass::ghsGatheringReport($order);
  762. }
  763. util::success(['returnStatus' => 'SUCCESS']);
  764. } else {
  765. //标记有没付成功的次数,原因有可能是余额不足等
  766. Yii::$app->redis->executeCommand('SETEX', [$codePayErrorKey, 1200, 'hasFail']);
  767. $msg = $response['msg'] ?? '';
  768. $retCode = $response['code'] ?? '';
  769. if ($retCode == 'BBS10000' || $retCode == 'BBS11105') {
  770. $shopId = $order->shopId;
  771. ShopExtClass::remindInputPassword($shopId);
  772. }
  773. $fullMsg = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
  774. //noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号007', '15280215347');
  775. util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
  776. }
  777. } catch (\Exception $e) {
  778. $transaction->rollBack();
  779. Yii::error("支付失败原因:" . $e->getMessage());
  780. util::fail('支付失败');
  781. }
  782. }
  783. //订单列表 ssh 2021.1.20
  784. public function actionList()
  785. {
  786. $get = Yii::$app->request->get();
  787. $export = $get['export'] ?? 0;
  788. $onlySend = $get['onlySend'] ?? 0;
  789. ini_set('memory_limit', '5045M');
  790. set_time_limit(0);
  791. $staff = $this->shopAdmin;
  792. if (isset($staff->identity) && $staff->identity == 2) {
  793. //如果用于确认发货时要显出订单
  794. if ($onlySend == 0) {
  795. util::success(['list' => []]);
  796. }
  797. }
  798. $where['mainId'] = $this->mainId;
  799. $status = $get['status'] ?? 0;
  800. if (!empty($status)) {
  801. $where['status'] = $status;
  802. }
  803. $clearSign = $get['clearSign'] ?? -1;
  804. if ($clearSign > -1) {
  805. $where['clearSign'] = $clearSign;
  806. }
  807. $book = $get['book'] ?? -1;
  808. if ($book > -1) {
  809. $where['book'] = $book;
  810. }
  811. $searchTime = $get['searchTime'] ?? '';
  812. if (!empty($searchTime)) {
  813. $startTime = $get['startTime'] ?? '';
  814. $endTime = $get['endTime'] ?? '';
  815. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  816. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  817. }
  818. if ($export == 1) {
  819. ini_set('memory_limit', '2045M');
  820. set_time_limit(0);
  821. if (isset($where['payTime']) == false) {
  822. util::fail('请选时间段');
  823. }
  824. $start = $where['payTime'][1][0];
  825. $end = $where['payTime'][1][1];
  826. $monthTime = bcmul(31, 86400);
  827. $startArea = strtotime($start);
  828. $endArea = strtotime($end);
  829. $diff = bcsub($endArea, $startArea);
  830. if ($diff > $monthTime) {
  831. util::fail('最长可导出一个月');
  832. }
  833. }
  834. $name = $get['name'] ?? '';
  835. if (!empty($name)) {
  836. $searchType = $get['searchType'] ?? 0;
  837. if (empty($searchType)) {
  838. //订单编号
  839. if (strpos($name, 'XSD') === 0) {
  840. $where['orderSn'] = $name;
  841. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  842. $where['customNamePy'] = ['like', $name];
  843. } else {
  844. $where['customName'] = ['like', $name];
  845. }
  846. } elseif ($searchType == 1) {
  847. $where['sendNum'] = $name;
  848. } else {
  849. }
  850. }
  851. if (isset($get['customId']) && !empty($get['customId'])) {
  852. $where['customId'] = $get['customId'];
  853. }
  854. if (isset($get['ids']) && !empty($get['ids'])) {
  855. $stringIds = $get['ids'];
  856. $newIds = explode(',', $stringIds);
  857. $where['id'] = ['in', $newIds];
  858. }
  859. //选择开单人
  860. $shopAdminId = $get['shopAdminId'] ?? 0;
  861. if (!empty($shopAdminId)) {
  862. $where['shopAdminId'] = $shopAdminId;
  863. }
  864. $respond = OrderClass::getOrderList($where);
  865. if ($export == 1) {
  866. OrderClass::exportOrderData($respond, $this->mainId);
  867. }
  868. $respond['shop'] = $this->shop;
  869. $respond['shopExt'] = $this->shopExt;
  870. util::success($respond);
  871. }
  872. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  873. public function actionNewOrderList()
  874. {
  875. $get = Yii::$app->request->get();
  876. $where['shopId'] = $this->shopId;
  877. /*$status = $get['status'] ?? 0;
  878. if (!empty($status)) {
  879. $where['status'] = $status;
  880. }*/
  881. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  882. if (isset($get['type'])) {
  883. $type = $get['type'];
  884. if ($type == 1) { // 今日实收
  885. $get['searchTime'] = 'today';
  886. $where['debt'] = 0;
  887. $where['debtPrice'] = '0.00';
  888. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  889. } elseif ($type == 2) { // 今日欠款
  890. $get['searchTime'] = 'today';
  891. $where['debt'] = 1;
  892. } elseif ($type == 3) { // 总欠款
  893. $where['debt'] = 1;
  894. } else {
  895. util::fail('查询的订单类别不存在');
  896. }
  897. }
  898. $searchTime = $get['searchTime'] ?? '';
  899. if (!empty($searchTime)) {
  900. $startTime = '';
  901. $endTime = '';
  902. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  903. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  904. }
  905. $name = $get['name'] ?? '';
  906. if (!empty($name)) {
  907. $searchType = $get['searchType'] ?? 0;
  908. if (empty($searchType)) {
  909. //订单编号
  910. if (strpos($name, 'XSD') === 0) {
  911. $where['orderSn'] = $name;
  912. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  913. $where['customNamePy'] = ['like', $name];
  914. } else {
  915. $where['customName'] = ['like', $name];
  916. }
  917. } elseif ($searchType == 1) {
  918. $where['sendNum'] = $name;
  919. } else {
  920. util::fail('搜索的订单类别不存在');
  921. }
  922. }
  923. $respond = OrderClass::getOrderList($where);
  924. $respond['shop'] = $this->shop;
  925. $respond['shopExt'] = $this->shopExt;
  926. $respond['type'] = $type; //把查询类别返回
  927. util::success($respond);
  928. }
  929. //商城下单操作 ssh 2021.1.14
  930. public function actionCreateOrder()
  931. {
  932. $form = new CreateOrderForm();
  933. $form->loadAndValidate();
  934. $post = $form->getAttributes();
  935. $shopId = $this->shopId;
  936. $customId = $post['customId'];
  937. $modifyPrice = $post['modifyPrice'] ?? 0;
  938. $pattern = '/^\d+(\.\d{1,2})?$/';
  939. if ($modifyPrice > 0) {
  940. if (!preg_match($pattern, $modifyPrice)) {
  941. //容错前端
  942. util::fail('金额不能超2位小数');
  943. }
  944. }
  945. $custom = CustomClass::getCustom($customId);
  946. if (empty($custom)) {
  947. util::fail('请选客户哦');
  948. }
  949. $shopAdmin = $this->shopAdmin;
  950. $shopAdminId = $this->shopAdminId;
  951. $shopAdminName = $shopAdmin->name ?? '';
  952. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  953. $dealPrice = $post['dealPrice'] ?? 0;
  954. //解决重复提交问题
  955. util::checkRepeatCommit($this->adminId . '_' . $dealPrice, 3);
  956. CustomClass::valid($custom, $this->shopId);
  957. if (!empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  958. util::fail('不能给自己开单');
  959. }
  960. $post['ghsId'] = $custom['ghsId'] ?? 0;
  961. $post['customMobile'] = $custom['mobile'] ?? '';
  962. $customName = $custom['name'] ?? '';
  963. $post['customName'] = $customName;
  964. $post['customNamePy'] = $custom['py'] ?? '';
  965. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  966. $post['province'] = $custom['province'] ?? '';
  967. $post['city'] = $custom['city'] ?? '';
  968. $post['dist'] = $custom['dist'] ?? '';
  969. $post['address'] = $custom['address'] ?? '';
  970. $post['floor'] = $custom['floor'] ?? '';
  971. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  972. $post['showAddress'] = $custom['showAddress'] ?? '';
  973. $post['long'] = $custom['long'] ?? '';
  974. $post['lat'] = $custom['lat'] ?? '';
  975. if (!empty($post['getStaffId'])) {
  976. if (getenv('YII_ENV') == 'production') {
  977. $tbMainId = 44171;
  978. } else {
  979. $tbMainId = 0;
  980. }
  981. if ($this->mainId == $tbMainId) {
  982. //平潭花天下,就算选了收款人,也不要给改变开单人,临时解决方案 ssh 2250314
  983. if (!empty($post['shopAdminId'])) {
  984. $getStaffName = $post['shopAdminName'] ?? '';
  985. $shopAdminId = $post['shopAdminId'];
  986. $shopAdminName = $getStaffName;
  987. }
  988. } else {
  989. $getStaffName = $post['getStaffName'] ?? '';
  990. $shopAdminId = $post['getStaffId'];
  991. $shopAdminName = $getStaffName;
  992. }
  993. } else {
  994. if (getenv('YII_ENV') == 'production') {
  995. //鹏诚需要选择开单人
  996. if (in_array($this->mainId, [19606])) {
  997. util::fail('请选择开单人');
  998. }
  999. } else {
  1000. if (in_array($this->mainId, [])) {
  1001. util::fail('请选择开单人');
  1002. }
  1003. }
  1004. }
  1005. if (getenv('YII_ENV') == 'production') {
  1006. //小向花卉开单售后控制
  1007. if ($this->mainId == 23390) {
  1008. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960, 28456, 31105, 28456, 31105, 52528, 25011, 61449, 77951])) {
  1009. util::fail('你不能开单哦');
  1010. }
  1011. }
  1012. }
  1013. //开单人和收款人必定是同个人
  1014. $post['shopAdminId'] = $shopAdminId;
  1015. $post['shopAdminName'] = $shopAdminName;
  1016. $post['getStaffId'] = $shopAdminId;
  1017. $post['getStaffName'] = $shopAdminName;
  1018. $post['sjId'] = $this->sjId;
  1019. $post['shopId'] = $shopId;
  1020. $post['mainId'] = $this->mainId;
  1021. $post['fromType'] = 1;
  1022. $post['expressId'] = $post['expressId'] ?? 0;
  1023. $book = $post['book'] ?? 0;
  1024. $post['book'] = $book;
  1025. $sendType = $post['sendType'] ?? 0;
  1026. $transType = $post['transType'] ?? 0;
  1027. $shop = $this->shop;
  1028. //过期不支持开单
  1029. $deadline = $shop->deadline;
  1030. $deadTime = strtotime($deadline);
  1031. $myCurrentTime = time();
  1032. $myCurrentDeadline = $deadTime;
  1033. if ($myCurrentTime > $myCurrentDeadline) {
  1034. util::fail('系统已到期,请续费哦');
  1035. }
  1036. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  1037. //昆明发往全国
  1038. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1039. $post['sendCost'] = $sendCost;
  1040. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1041. $post['packCost'] = $packCost;
  1042. $post['transType'] = $transType;
  1043. $post['localOrder'] = 1;
  1044. } else {
  1045. //同步配送
  1046. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1047. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  1048. util::fail('填了运费,请选择跑腿');
  1049. }
  1050. $post['sendCost'] = $sendCost;
  1051. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1052. }
  1053. if ($book == 1) {
  1054. $bookSn = $shop->bookSn ?? 0;
  1055. if (empty($bookSn)) {
  1056. util::fail('请开启预订');
  1057. }
  1058. $post['bookSn'] = $bookSn;
  1059. }
  1060. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  1061. $post['debt'] = OrderClass::DEBT_NO;
  1062. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  1063. $post['debt'] = OrderClass::DEBT_YES;
  1064. }
  1065. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1066. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  1067. //util::fail('没有权限');
  1068. }
  1069. }
  1070. if (getenv('YII_ENV') == 'production') {
  1071. if ($this->mainId == 1082) {
  1072. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1073. if ($hasPay != 0) {
  1074. util::fail('只能使用扫码付款,编号193');
  1075. }
  1076. }
  1077. //小齐鲜花出车,不能使用线下收款
  1078. if ($this->mainId == 42680) {
  1079. if ($hasPay == 1) {
  1080. util::fail('线下收款暂时无法使用');
  1081. }
  1082. }
  1083. } else {
  1084. if ($this->mainId == 644) {
  1085. if ($hasPay == 1) {
  1086. util::fail('线下收款暂时无法使用');
  1087. }
  1088. }
  1089. }
  1090. //多颜色数据整理
  1091. $colorItem = $post['xj'] ?? [];
  1092. $newXj = [];
  1093. if (!empty($colorItem)) {
  1094. $colorData = json_decode($colorItem, true);
  1095. if (!empty($colorData) && is_array($colorData)) {
  1096. foreach ($colorData as $colorInfo) {
  1097. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  1098. $colorList = $colorInfo['list'] ?? [];
  1099. if (!empty($colorList)) {
  1100. foreach ($colorList as $colorItemKey => $colorItem) {
  1101. $newXj[$ptItemId][] = $colorItem;
  1102. }
  1103. }
  1104. }
  1105. }
  1106. }
  1107. $post['xj'] = $newXj;
  1108. $productJson = $post['product'];
  1109. $productList = json_decode($productJson, true);
  1110. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  1111. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  1112. if (empty($itemInfo)) {
  1113. util::fail('请选择花材哦');
  1114. }
  1115. //判断花材有效性
  1116. foreach ($itemInfo as $itemData) {
  1117. if (!isset($itemData['mainId']) || $itemData['mainId'] != $this->mainId) {
  1118. util::fail('只能选择同一家的商品哈');
  1119. }
  1120. }
  1121. $diff = [];
  1122. $priceMap = CustomClass::$levelPriceKeyMap;
  1123. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  1124. $level = $custom['level'] ?? 1;
  1125. foreach ($productList as $currentProduct) {
  1126. $currentPrice = $currentProduct['price'] ?? 0;
  1127. $currentId = $currentProduct['productId'] ?? 0;
  1128. $systemInfo = $itemInfo[$currentId] ?? [];
  1129. $name = $systemInfo['name'] ?? '';
  1130. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  1131. if (getenv('YII_ENV') == 'production') {
  1132. //苏州小蔡鲜花,几个出车,不能低于原价卖,但可以高于原价卖的
  1133. if (in_array($shopId, [38231, 38143, 29163, 29161])) {
  1134. if ($currentPrice < $systemPrice) {
  1135. util::fail('不能低于原价卖');
  1136. }
  1137. }
  1138. } else {
  1139. if (in_array($shopId, [36544])) {
  1140. if ($currentPrice < $systemPrice) {
  1141. util::fail('不能低于原价卖');
  1142. }
  1143. }
  1144. }
  1145. if (floatval($currentPrice) != floatval($systemPrice)) {
  1146. $diff[] = [
  1147. 'name' => $name,
  1148. 'price' => $systemPrice,
  1149. 'kdPrice' => $currentPrice,
  1150. ];
  1151. }
  1152. }
  1153. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  1154. if ($dealPrice == 0) {
  1155. if (!empty($diff)) {
  1156. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  1157. }
  1158. } else {
  1159. if (!empty($diff)) {
  1160. $mainId = $this->mainId;
  1161. //花样年华,除了老板,只能按原价开单,不能改价格
  1162. if (getenv('YII_ENV') == 'production') {
  1163. if (in_array($mainId, [1553, 1563])) {
  1164. if ($this->adminId != 2876) {
  1165. util::fail('请按花材原价格开单');
  1166. }
  1167. }
  1168. } else {
  1169. if (in_array($mainId, [0, 1])) {
  1170. util::fail('请按花材原价格开单');
  1171. }
  1172. }
  1173. }
  1174. }
  1175. if ($book == 1) {
  1176. $post['hasPay'] = 2;
  1177. $post['payWay'] = 0;
  1178. }
  1179. $historyDate = $post['historyDate'] ?? '';
  1180. if (!empty($historyDate)) {
  1181. if ($book == 1) {
  1182. util::fail('预订单不能选订单日期');
  1183. }
  1184. if ($hasPay == 0) {
  1185. util::fail('扫码付不能选订单日期');
  1186. }
  1187. if (strtotime($historyDate) > strtotime(date("Y-m-d"))) {
  1188. util::fail('订单日期只能选历史时间');
  1189. }
  1190. }
  1191. $connection = Yii::$app->db;
  1192. $transaction = $connection->beginTransaction();
  1193. try {
  1194. $post['product'] = $productList;
  1195. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  1196. $time = time();
  1197. $hasTime = dict::getDict('order_pay_has_time');
  1198. $totalTime = bcadd($time, $hasTime);
  1199. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  1200. //多处有用到此方法,需要同步修改,搜索关键词create_new_order
  1201. $return = OrderService::createNewOrder($post, $custom, $hasPay);
  1202. $transaction->commit();
  1203. $saleId = $return->id ?? 0;
  1204. $order = OrderClass::getById($saleId, true);
  1205. if (!empty($order)) {
  1206. $shopId = $order->shopId ?? 0;
  1207. $customId = $order->customId ?? 0;
  1208. $ghsId = $order->ghsId ?? 0;
  1209. $custom = CustomClass::getById($customId, true);
  1210. $date = date("Y-m-d H:i:s");
  1211. if (!empty($custom)) {
  1212. $custom->recentExpend = $date;
  1213. $custom->save();
  1214. }
  1215. $ghs = GhsClass::getById($ghsId, true);
  1216. if (!empty($ghs)) {
  1217. $ghs->recentExpend = $date;
  1218. $ghs->save();
  1219. }
  1220. $shop = ShopClass::getById($shopId, true);
  1221. if (isset($order->payStatus) && $order->payStatus == 1) {
  1222. if (!empty($shop)) {
  1223. GhsNotifyClass::newOrderNotify($saleId);
  1224. HdNotifyClass::newCgNotify($order->purchaseId);
  1225. }
  1226. }
  1227. //订单生成时唤起在线打印
  1228. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1229. //预订单开单不打小票,小向花卉不需要打小票
  1230. $mainId = $order->mainId ?? 0;
  1231. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1232. if ($order->status != 1 && $order->status != 5) {
  1233. OrderClass::onlinePrint($order);
  1234. $ext = $this->shopExt;
  1235. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1236. $order->printNum += 1;
  1237. $order->save();
  1238. }
  1239. //花镜 自己开单要打二次,有多处要修改搜索关键词 tow_print
  1240. if (in_array($mainId, [76796])) {
  1241. OrderClass::onlinePrint($order);
  1242. $ext = $this->shopExt;
  1243. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1244. $order->printNum += 1;
  1245. $order->save();
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. //前台提醒出示付款码
  1252. if (isset($order->status) && $order->status == 1) {
  1253. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1254. ShopExtClass::ghsPleasePayReport($order);
  1255. }
  1256. }
  1257. //跑腿订单生产者创建订单
  1258. // TODO
  1259. if ($order->payStatus == 1 && $sendType == dict::getDict('sendType', 'thirdSend') && $post['callErrand'] == 1) { // $post 中有 pickupTime,则说明是要立即发跑腿 或者 callErrand == 1
  1260. $platform = $post['deliveryPlatform'];
  1261. $deliveryPrice = $post['deliveryPrice'];
  1262. $deliveryDistance = $post['deliveryDistance'];
  1263. $deliveryBracketContent = $post['deliveryBracketContent'];
  1264. $pickupTime = $post['pickupTime'];
  1265. $allParams = $post['deliveryAllParams'];
  1266. $data = [
  1267. 'orderId' => $saleId,
  1268. 'shopId' => $this->shopId,
  1269. 'mainId' => $this->mainId,
  1270. 'platform' => $platform,
  1271. 'ip' => Yii::$app->request->userIP,
  1272. 'deliveryPrice' => $deliveryPrice,
  1273. 'deliveryDistance' => $deliveryDistance,
  1274. 'deliveryBracketContent' => $deliveryBracketContent,
  1275. 'pickupTime' => $pickupTime,
  1276. 'allParmas' => $allParams,
  1277. // ----------
  1278. 'weight' => $post['weight'] ?? 1,
  1279. 'remark' => $post['deliveryRemark'] ?? '',
  1280. 'price' => $order->actPrice,
  1281. ];
  1282. GhsDeliveryOrderClass::askCreateOrder($data);
  1283. }
  1284. }
  1285. util::success($return);
  1286. } catch (\Exception $e) {
  1287. $transaction->rollBack();
  1288. Yii::error("下单失败原因:" . $e->getMessage());
  1289. noticeUtil::push("批发线下开单失败,原因:" . $e->getMessage(), '15280215347');
  1290. util::fail('下单失败');
  1291. }
  1292. }
  1293. //修改订单 ssh 20210810
  1294. public function actionUpdateOrder()
  1295. {
  1296. $post = Yii::$app->request->post();
  1297. util::fail('订单不可修改');
  1298. //PC端开单
  1299. if (isset($post['clearType'])) {
  1300. $clearType = $post['clearType'];
  1301. if ($clearType == OrderClass::CLEAR_DEBT) {
  1302. $post['debt'] = OrderClass::DEBT_YES;
  1303. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1304. } else {
  1305. $post['debt'] = OrderClass::DEBT_NO;
  1306. }
  1307. }
  1308. //员工不能开已收款订单
  1309. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1310. if ($debt == OrderClass::DEBT_NO) {
  1311. $shopAdmin = $this->shopAdmin;
  1312. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1313. util::fail('不能开已收款订单');
  1314. }
  1315. }
  1316. //PC端开单
  1317. if (isset($post['getType'])) {
  1318. util::fail('暂不支持PC端修改订单');
  1319. $getType = $post['getType'];
  1320. //自取
  1321. if ($getType == 1) {
  1322. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1323. } else {
  1324. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1325. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1326. }
  1327. }
  1328. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1329. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1330. $post['debt'] = OrderClass::DEBT_NO;
  1331. }
  1332. $id = $post['id'] ?? 0;
  1333. $order = OrderClass::getLockById($id);
  1334. if (empty($order)) {
  1335. util::fail('没有找到订单');
  1336. }
  1337. OrderClass::valid($order, $this->shopId);
  1338. unset($post['id']);
  1339. $shopAdmin = $this->shopAdmin;
  1340. $post['shopAdminId'] = $this->shopAdminId;
  1341. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1342. $post['fromType'] = 1;
  1343. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1344. $productJson = $post['product'] ?? '';
  1345. if (empty($productJson)) {
  1346. util::fail('请选择花材');
  1347. }
  1348. $productList = json_decode($productJson, true);
  1349. if (empty($productList)) {
  1350. util::fail('请选择花材');
  1351. }
  1352. $connection = Yii::$app->db;
  1353. $transaction = $connection->beginTransaction();
  1354. try {
  1355. //判断花材有效性
  1356. ProductClass::valid($productList, $this->mainId);
  1357. $post['product'] = $productList;
  1358. //商家开单订单有效期,到期记欠款
  1359. $validTime = dict::getDict('order_pay_has_time');
  1360. $current = time() + $validTime;
  1361. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1362. $upData = [
  1363. 'payWay' => $post['payWay'],
  1364. 'sendType' => $post['sendType'],
  1365. 'debt' => $post['debt'],
  1366. 'needPrint' => $post['needPrint'],
  1367. 'modifyPrice' => $post['modifyPrice'],
  1368. 'shopAdminId' => $post['shopAdminId'],
  1369. 'shopAdminName' => $post['shopAdminName'],
  1370. 'fromType' => 1,
  1371. 'sendCost' => $post['sendCost'],
  1372. 'product' => $post['product'],
  1373. 'deadline' => $post['deadline'],
  1374. 'debt' => $post['debt'],
  1375. ];
  1376. $return = OrderService::updateOrder($order, $upData);
  1377. $transaction->commit();
  1378. util::success($return);
  1379. } catch (\Exception $e) {
  1380. $transaction->rollBack();
  1381. Yii::error("下单失败原因:" . $e->getMessage());
  1382. util::fail('下单失败');
  1383. }
  1384. }
  1385. //取消预订单 ssh 20240503
  1386. public function actionCancelBookOrder()
  1387. {
  1388. $get = Yii::$app->request->get();
  1389. $id = $get['id'] ?? 0;
  1390. if (empty($id)) {
  1391. util::fail('请选择订单');
  1392. }
  1393. $order = OrderClass::getById($id, true);
  1394. if (empty($order)) {
  1395. util::fail('没有找到订单');
  1396. }
  1397. OrderClass::valid($order, $this->shopId);
  1398. if ($order->book == 0) {
  1399. util::fail('不是预订单');
  1400. }
  1401. if ($order->status != 2) {
  1402. util::fail('当前订单状态不能取消');
  1403. }
  1404. $purchaseId = $order->purchaseId ?? 0;
  1405. $purchase = PurchaseClass::getById($purchaseId, true);
  1406. if (empty($purchase)) {
  1407. util::fail('没有找到采购单');
  1408. }
  1409. $connection = Yii::$app->db;
  1410. $transaction = $connection->beginTransaction();
  1411. try {
  1412. $order->status = 5;
  1413. $order->save();
  1414. $purchase->status = 5;
  1415. $purchase->save();
  1416. $transaction->commit();
  1417. util::complete('取消成功');
  1418. } catch (\Exception $e) {
  1419. $transaction->rollBack();
  1420. $msg = $e->getMessage();
  1421. $orderSn = $order->orderSn ?? '';
  1422. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1423. }
  1424. }
  1425. //取消订单 shizhongqi 20220619
  1426. public function actionCancelOrder()
  1427. {
  1428. $post = Yii::$app->request->post();
  1429. $id = $post['orderId'] ?? 0;
  1430. if (empty($id)) {
  1431. util::fail('请选择订单');
  1432. }
  1433. $order = OrderClass::getById($id, true);
  1434. if (empty($order)) {
  1435. util::fail('请选择订单...');
  1436. }
  1437. OrderClass::valid($order, $this->shopId);
  1438. if (isset($order->status) == false || $order->status != 1) {
  1439. util::fail('不是待付款状态,无法取消');
  1440. }
  1441. $purchaseId = $order->purchaseId ?? 0;
  1442. $purchase = PurchaseClass::getById($purchaseId);
  1443. if (empty($purchase)) {
  1444. util::fail('没有找到采购单');
  1445. }
  1446. $deadLineTime = strtotime($purchase['deadline']);
  1447. $diff = $deadLineTime - time();
  1448. if ($diff <= 60) {
  1449. util::fail('1分钟后订单将自动取消');
  1450. }
  1451. $connection = Yii::$app->db;
  1452. $transaction = $connection->beginTransaction();
  1453. $orderSn = $purchase['orderSn'];
  1454. try {
  1455. $current = PurchaseClass::getById($purchaseId, true);
  1456. PurchaseService::expire($current);
  1457. $transaction->commit();
  1458. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1459. } catch (\Exception $e) {
  1460. $transaction->rollBack();
  1461. $msg = $e->getMessage();
  1462. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1463. }
  1464. util::complete();
  1465. }
  1466. //延期支付 ssh 2021.1.19
  1467. public function actionDebt()
  1468. {
  1469. $id = Yii::$app->request->get('id');
  1470. //4秒内不允许重复提交
  1471. $cacheKey = 'ghs_set_order_debt_' . $id;
  1472. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1473. if (!empty($has)) {
  1474. util::fail('请稍等');
  1475. }
  1476. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1477. if (getenv('YII_ENV') == 'production') {
  1478. if ($this->mainId == 1082) {
  1479. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1480. util::fail('只能使用扫码付款,编号293');
  1481. }
  1482. } else {
  1483. }
  1484. $order = OrderClass::getById($id, true);
  1485. OrderClass::valid($order, $this->shopId);
  1486. $payWay = dict::getDict('payWay', 'debtPay');
  1487. $cgId = $order->purchaseId ?? 0;
  1488. $cg = PurchaseClass::getById($cgId, true);
  1489. if (empty($cg)) {
  1490. util::fail('没有找到采购单');
  1491. }
  1492. if ($order->book == 1) {
  1493. util::fail('预订单不能记欠款');
  1494. }
  1495. $connection = Yii::$app->db;
  1496. $transaction = $connection->beginTransaction();
  1497. try {
  1498. PurchaseService::payAfter($cg, $payWay);
  1499. OrderService::payAfter($order, $payWay);
  1500. $transaction->commit();
  1501. } catch (\Exception $exception) {
  1502. $transaction->rollBack();
  1503. Yii::info("延期支付报错:" . $exception->getMessage());
  1504. util::fail('操作失败');
  1505. }
  1506. $order = OrderClass::getById($id, true);
  1507. if (!empty($order)) {
  1508. $shopId = $order->shopId ?? 0;
  1509. $shop = ShopClass::getById($shopId, true);
  1510. if (!empty($shop)) {
  1511. //花店采购供货商端微信收到通知
  1512. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1513. $noticeText = json_encode(['orderId' => $id]);
  1514. $noticeKey = "hdCgNoticeGhs";
  1515. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1516. }
  1517. //订单生成时唤起在线打印
  1518. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1519. if ($order->status != 1 && $order->status != 5) {
  1520. OrderClass::onlinePrint($order);
  1521. $ext = $this->shopExt;
  1522. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1523. $order->printNum += 1;
  1524. $order->save();
  1525. }
  1526. }
  1527. }
  1528. if ($order->status != 1 && $order->status != 5) {
  1529. //花店采购供货商端APP收到通知
  1530. //NoticeClass::ghsNewOrderNotice($order);
  1531. //向供货商APP发通知
  1532. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  1533. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  1534. // $push->ghsOrderMessage($shop, $cgShop, $order);
  1535. }
  1536. }
  1537. util::complete();
  1538. }
  1539. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1540. public function actionWxPay()
  1541. {
  1542. ini_set('date.timezone', 'Asia/Shanghai');
  1543. $post = Yii::$app->request->post();
  1544. $couponId = $post['couponId'] ?? 0;
  1545. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1546. $order = OrderClass::getByOrderSn($orderSn);
  1547. if (empty($order)) {
  1548. util::fail('订单号无效');
  1549. }
  1550. $id = $order['id'];
  1551. //支付前验证订单有效性
  1552. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1553. util::fail('无法操作');
  1554. }
  1555. $name = $order['orderName'] ?? '购买商品';
  1556. $totalFee = $order['actPrice'];
  1557. //强制使用小程序的miniOpenId
  1558. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1559. if (empty($openId)) {
  1560. util::fail('没有找到openId');
  1561. }
  1562. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1563. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1564. $wxPayType = 0;
  1565. if (httpUtil::isMiniProgram()) {
  1566. $wxPayType = 1;
  1567. }
  1568. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1569. //订单30分钟后过期
  1570. $now = time();
  1571. $expireTime = $now + 1800;
  1572. $wx = Yii::getAlias("@vendor/weixin");
  1573. require_once($wx . '/lib/WxPay.Api.php');
  1574. require_once($wx . '/example/WxPay.JsApiPay.php');
  1575. $input = new \WxPayUnifiedOrder();
  1576. $input->SetBody($name);
  1577. $input->SetOut_trade_no($orderSn);
  1578. $input->SetTotal_fee($totalFee * 100);
  1579. $input->SetTime_start(date("YmdHis", $now));
  1580. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1581. $input->SetTime_expire(date("YmdHis", $expireTime));
  1582. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1583. $input->SetTrade_type("JSAPI");
  1584. //花卉宝代为申请的微信支付
  1585. //$sjExtend = $this->sjExtend->attributes;
  1586. $sjExtend = WxOpenClass::getGhsWxInfo();
  1587. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1588. $input->SetSub_openid($openId);
  1589. } else {
  1590. $input->SetOpenid($openId);
  1591. }
  1592. //强制使用小程序的miniAppId
  1593. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1594. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1595. $tools = new \JsApiPay();
  1596. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1597. $newParams = json_decode($jsApiParameters, true);
  1598. //微信不能修改价格
  1599. $current = date("Y-m-d H:i:s");
  1600. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1601. OrderClass::updateById($id, $updateData);
  1602. util::success($newParams);
  1603. }
  1604. //获取订单详情 ssh 2021.1.21
  1605. public function actionDetail()
  1606. {
  1607. $get = Yii::$app->request->get();
  1608. $id = $get['id'] ?? 0;
  1609. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1610. OrderClass::valid($info, $this->shopId);
  1611. //A4打印需要用到的数据
  1612. $customId = $info['customId'] ?? 0;
  1613. $remark = $info['remark'] ?? '';
  1614. $sendCost = $info['sendCost'] ?? 0;
  1615. $sendNum = $info['sendNum'] ?? '';
  1616. $packCost = $info['packCost'] ?? 0;
  1617. $staffName = $info['shopAdminName'] ?? '';
  1618. $ysName = '';
  1619. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  1620. if ($info['transType'] == 0) {
  1621. $ysName = '德邦空运';
  1622. }
  1623. if ($info['transType'] == 1) {
  1624. $ysName = '顺丰空运';
  1625. }
  1626. if ($info['transType'] == 2) {
  1627. $ysName = '冷链物流';
  1628. }
  1629. if ($info['transType'] == 3) {
  1630. $ysName = '航空物流';
  1631. }
  1632. if ($info['transType'] == 4) {
  1633. $ysName = '同城配送';
  1634. }
  1635. if ($info['transType'] == 5) {
  1636. $ysName = '到店自取';
  1637. }
  1638. } else {
  1639. $sendType = $info['sendType'] ?? 0;
  1640. $ysName = '送货上门';
  1641. if ($sendType == 1) {
  1642. $ysName = '到店自取';
  1643. }
  1644. if ($sendType == 2) {
  1645. $ysName = '发跑腿';
  1646. }
  1647. if ($sendType == 3) {
  1648. $wlName = $info['wlName'] ?? '';
  1649. $ysName = '发物流';
  1650. if (!empty($wlName)) {
  1651. $ysName = $ysName . '-' . $wlName;
  1652. }
  1653. }
  1654. }
  1655. $fullAddress = '';
  1656. if (getenv('YII_ENV') == 'production') {
  1657. //老油的要显示地址
  1658. if ($this->mainId == 20528) {
  1659. $fullAddress = $info['fullAddress'] ?? '';
  1660. }
  1661. } else {
  1662. if ($this->mainId == 644) {
  1663. $fullAddress = $info['fullAddress'] ?? '';
  1664. }
  1665. }
  1666. $custom = CustomClass::getById($customId, true);
  1667. if (empty($custom)) {
  1668. util::fail('没有找到客户');
  1669. }
  1670. $customName = $custom->name ?? '';
  1671. $customMobile = $custom->customMobile ?? '';
  1672. if (empty($customMobile)) {
  1673. $customShopId = $custom->shopId ?? 0;
  1674. $customShop = ShopClass::getById($customShopId, true);
  1675. if (!empty($customShop)) {
  1676. $customMobile = $customShop->mobile ?? '';
  1677. }
  1678. }
  1679. if (!empty($customMobile)) {
  1680. $customMobile = substr_replace($customMobile, '****', 3, 4);
  1681. }
  1682. $fullCustom = $customName . ' ' . $customMobile;
  1683. if ($this->mainId == 8164) {
  1684. //花大苪不显示客户名称
  1685. $fullCustom = '';
  1686. }
  1687. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  1688. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1689. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1690. $totalItemNum = 0;
  1691. $totalSmallItemNum = 0;
  1692. $table = [];
  1693. if (isset($info['product']) && !empty($info['product'])) {
  1694. foreach ($info['product'] as $key => $val) {
  1695. $currentName = $val['name'] ?? '';
  1696. $num = $val['xhNum'] ?? 0;
  1697. $refundNum = $val['refundNum'] ?? 0;
  1698. $num = bcsub($num, $refundNum);
  1699. $totalItemNum = bcadd($totalItemNum, $num);
  1700. $ratio = $val['ratio'] ?? 0;
  1701. $currentSmallNum = bcmul($num, $ratio);
  1702. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1703. $itemRemark = $val['remark'] ?? '';
  1704. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1705. $unitPrice = floatval($unitPrice);
  1706. $price = bcmul($unitPrice, $num, 2);
  1707. $price = floatval($price);
  1708. $table[] = [
  1709. 'name' => $currentName,
  1710. 'num' => $num,
  1711. 'confirmNum' => '',
  1712. 'remark' => $itemRemark,
  1713. 'wxNumber' => 'shish3508',
  1714. 'unitPrice' => $unitPrice,
  1715. 'price' => $price,
  1716. ];
  1717. }
  1718. }
  1719. $shop = $this->shop;
  1720. $sjName = $shop->merchantName ?? '';
  1721. $shopName = $shop->shopName ?? '';
  1722. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1723. $a4Print = [
  1724. 'customName' => $fullCustom,
  1725. 'staffName' => $staffName,
  1726. 'seatSn' => $seatSn,
  1727. 'shortSendTimeWant' => $shortSendTimeWant,
  1728. 'table' => $table,
  1729. 'remark' => $remark,
  1730. 'fullAddress' => $fullAddress,
  1731. 'sendNum' => $sendNum,
  1732. 'sendCost' => $sendCost,
  1733. 'ysName' => $ysName,
  1734. 'packCost' => $packCost,
  1735. 'totalItemNum' => $totalItemNum,
  1736. 'totalSmallItemNum' => $totalSmallItemNum,
  1737. 'shopName' => $sjShopName . ' 销售单',
  1738. ];
  1739. $info['printData'] = $a4Print;
  1740. //常规模板
  1741. //有用的历史备份
  1742. $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":150,"height":45,"width":535,"title":"备注","right":565.75,"bottom":195,"vCenter":298.25,"hCenter":172.5,"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":25,"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,"textContentVerticalAlign":"middle"},"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,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":90,"top":135,"height":15,"width":79,"title":"德邦物流","right":173.9921875,"bottom":150,"vCenter":134.4921875,"hCenter":142.5,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":174,"top":135,"height":15,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":135,"height":15,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375,"textContentVerticalAlign":"middle"},"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}}]}';
  1743. //$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}}]}';
  1744. if (getenv('YII_ENV') == 'production') {
  1745. //花大苪模板
  1746. if (in_array($this->mainId, [8164])) {
  1747. $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":{}}]}';
  1748. }
  1749. if (in_array($this->mainId, [44282])) {
  1750. //$template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":73.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":77,"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":53,"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":50.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":50.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":181.5,"height":45,"width":535,"title":"备注","right":565.75,"bottom":195,"vCenter":298.25,"hCenter":172.5,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":137.5,"height":25,"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,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":165,"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,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":90,"top":165,"height":15,"width":79,"title":"德邦物流","right":173.9921875,"bottom":150,"vCenter":134.4921875,"hCenter":142.5,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":174,"top":165,"height":15,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":165,"height":15,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":25.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}}]}';
  1751. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":73.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":77,"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","fontSize":11.25,"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":53,"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":50.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":93,"top":51,"height":19,"width":411,"title":"文本","right":503.49609375,"bottom":69.49609375,"vCenter":297.99609375,"hCenter":59.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":181.5,"height":45,"width":535,"title":"备注","right":565.75,"bottom":195,"vCenter":298.25,"hCenter":172.5,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":137.5,"height":25,"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,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":165,"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,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":90,"top":165,"height":15,"width":79,"title":"德邦物流","right":173.9921875,"bottom":150,"vCenter":134.4921875,"hCenter":142.5,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":174,"top":165,"height":15,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":165,"height":15,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":25.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}}]}';
  1752. }
  1753. }
  1754. $info['template'] = $template;
  1755. $printType = $get['printType'] ?? 0;
  1756. if ($printType == 1) {
  1757. //打多联的模板
  1758. $table = [];
  1759. if (isset($info['product']) && !empty($info['product'])) {
  1760. foreach ($info['product'] as $key => $val) {
  1761. $currentName = $val['name'] ?? '';
  1762. $num = $val['xhNum'] ?? 0;
  1763. $refundNum = $val['refundNum'] ?? 0;
  1764. $num = bcsub($num, $refundNum);
  1765. $totalItemNum = bcadd($totalItemNum, $num);
  1766. $ratio = $val['ratio'] ?? 0;
  1767. $currentSmallNum = bcmul($num, $ratio);
  1768. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1769. $itemRemark = $val['remark'] ?? '';
  1770. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1771. $unitPrice = floatval($unitPrice);
  1772. $price = bcmul($unitPrice, $num, 2);
  1773. $price = floatval($price);
  1774. $table[] = [
  1775. 'name' => $currentName,
  1776. 'num' => $num,
  1777. 'orderNum' => '',
  1778. 'remark' => $itemRemark,
  1779. 'wxNumber' => 'shish3508',
  1780. 'unitPrice' => '¥' . $unitPrice,
  1781. 'price' => '¥' . $price,
  1782. 'refundNum' => $refundNum == 0 ? '' : 0,
  1783. ];
  1784. }
  1785. }
  1786. $orderSn = $info['orderSn'] ?? '';
  1787. $kind = $info['productStat'] && $info['productStat']['kind'] ?? 0;
  1788. $totalItemNum = $info['productStat'] && $info['productStat']['bigNum'] ?? 0;
  1789. $addTime = $info['addTime'] ?? '';
  1790. $actPrice = $info['actPrice'] ?? 0;
  1791. $tkPrice = $info['tkPrice'] ?? 0;
  1792. $prePrice = $info['prePrice'] ?? 0;
  1793. $customMobile = $info['customMobile'] ?? '';
  1794. $address = '';
  1795. if (isset($info['address']) && !empty($info['address'])) {
  1796. $address .= $info['fullAddress'];
  1797. if (isset($info['showAddress']) && !empty($info['showAddress']) && $info['showAddress'] != $info['fullAddress']) {
  1798. $address .= '(' . $info['showAddress'] . ')<BR>';
  1799. }
  1800. }
  1801. $printData = [
  1802. 'table' => $table,
  1803. 'addTime' => '',
  1804. 'entryTime' => $addTime,
  1805. 'ghsName' => $customName,
  1806. 'clearCode' => '',
  1807. 'staffName' => '',
  1808. 'telephone' => $customMobile,
  1809. 'kind' => $kind,
  1810. 'orderSn' => $orderSn,
  1811. 'sjShopName' => $sjShopName . ' 销售单',
  1812. 'prePrice' => '¥' . $prePrice,
  1813. 'tkPrice' => '¥' . $tkPrice,
  1814. 'realPrice' => '¥' . $actPrice,
  1815. 'totalItemNum' => $totalItemNum,
  1816. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  1817. 'address' => $address,
  1818. ];
  1819. $info['printData'] = $printData;
  1820. $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":49.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName","testData":"小向花卉 采购单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":55,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"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":200,"top":120,"height":16,"width":178,"title":"账单日期","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":372,"top":120,"height":16,"width":178,"title":"客户","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"创建时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":169.5,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":169.5,"top":169.5,"height":16,"width":400,"title":"地址","field":"address","testData":"厦门前山路147号","coordinateSync":false,"widthHeightSync":false,"fontSize":10.5,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":569.5,"bottom":185.5,"vCenter":369.5,"hCenter":177.5},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"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}}]}';
  1821. $info['template'] = $template;
  1822. }
  1823. //是否有云打印判断
  1824. $hasCloudPrint = 0;
  1825. $shopExt = $this->shopExt;
  1826. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1827. $hasCloudPrint = 1;
  1828. }
  1829. $info['hasCloudPrint'] = $hasCloudPrint;
  1830. $purchaseId = $info['purchaseId'] ?? 0;
  1831. $cg = PurchaseClass::getById($purchaseId);
  1832. $info['cgInfo'] = $cg;
  1833. //店长信息
  1834. $mainId = $cg['mainId'] ?? 0;
  1835. $superInfo = ShopAdminClass::getManager($mainId);
  1836. $info['customSuper'] = $superInfo;
  1837. //员工是否有财务权限 ssh 20251117
  1838. $staff = $this->shopAdmin;
  1839. $staffFinance = $staff->finance ?? 0;
  1840. $info['staffFinance'] = $staffFinance;
  1841. util::success($info);
  1842. }
  1843. //获取订单信息 ssh 20240102
  1844. public function actionGetInfoByOrderSn()
  1845. {
  1846. $get = Yii::$app->request->get();
  1847. $orderSn = $get['orderSn'] ?? '';
  1848. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  1849. if (empty($info)) {
  1850. util::fail('没有找到订单');
  1851. }
  1852. if ($info->mainId != $this->mainId) {
  1853. util::fail('不是你的订单哦');
  1854. }
  1855. util::success(['info' => $info]);
  1856. }
  1857. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1858. public function actionInfo()
  1859. {
  1860. $get = Yii::$app->request->get();
  1861. $id = $get['id'] ?? 0;
  1862. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1863. if (empty($info)) {
  1864. util::fail('没有找到订单');
  1865. }
  1866. //是否有云打印判断
  1867. $hasCloudPrint = 0;
  1868. $shopExt = $this->shopExt;
  1869. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1870. $hasCloudPrint = 1;
  1871. }
  1872. $info['hasCloudPrint'] = $hasCloudPrint;
  1873. $purchaseId = $info['purchaseId'] ?? 0;
  1874. $cg = PurchaseClass::getById($purchaseId);
  1875. $info['cgInfo'] = $cg;
  1876. //店长信息
  1877. $mainId = $cg['mainId'] ?? 0;
  1878. $superInfo = ShopAdminClass::getManager($mainId);
  1879. $info['customSuper'] = $superInfo;
  1880. util::success($info);
  1881. }
  1882. //自取免发货流程处理 ssh 2021.1.22
  1883. public function actionWithoutSend()
  1884. {
  1885. util::complete();
  1886. }
  1887. //本店送 ssh 2021.1.24
  1888. public function actionSelfSend()
  1889. {
  1890. $get = Yii::$app->request->get();
  1891. $id = isset($get['id']) ? $get['id'] : 0;
  1892. $info = OrderClass::getById($id, true);
  1893. OrderClass::valid($info->attributes, $this->shopId);
  1894. $connection = Yii::$app->db;
  1895. $transaction = $connection->beginTransaction();
  1896. try {
  1897. OrderClass::selfSend($info);
  1898. $transaction->commit();
  1899. } catch (\Exception $exception) {
  1900. $transaction->rollBack();
  1901. Yii::info("本店送操作报错:" . $exception->getMessage());
  1902. util::fail('操作失败');
  1903. }
  1904. util::complete();
  1905. }
  1906. //运费计算 ssh 2021.1.24
  1907. public function actionFreight()
  1908. {
  1909. //2021.3.28 接入达达
  1910. $get = Yii::$app->request->get();
  1911. $post = Yii::$app->request->post();
  1912. if (empty($get)) {
  1913. $get = $post;
  1914. }
  1915. $orderId = $get['id'] ?? 0; //订单ID
  1916. $customId = $get['customId'] ?? 0;
  1917. if (empty($orderId)) {
  1918. //自定义运费
  1919. //freight::getCost();
  1920. if (empty($customId)) {
  1921. util::fail("请选择客户");
  1922. }
  1923. $customInfo = CustomClass::getById($customId);
  1924. if (empty($customInfo)) {
  1925. util::fail('没有找到客户');
  1926. }
  1927. $shop = $this->shop;
  1928. //花材信息
  1929. $productJson = $get['product'] ?? '';
  1930. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1931. if (empty($productJson)) {
  1932. util::fail('请选择花材');
  1933. }
  1934. $productList = json_decode($productJson, true);
  1935. if (empty($productList)) {
  1936. util::fail('请选择花材');
  1937. }
  1938. $productList = ProductClass::mergeItemInfo($productList);
  1939. $weight = 0;
  1940. $price = 0;
  1941. $productData = ProductClass::getProductMapData($productList);
  1942. $bigNum = 0;
  1943. foreach ($productList as $key => $val) {
  1944. $productId = $val['productId'];
  1945. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1946. $bigNum += $val['bigNum'];
  1947. $weight = bcadd($w, $weight, 2);
  1948. $ratio = $productData[$productId]['ratio'] ?? 0;
  1949. //大小数量合并多少扎
  1950. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1951. //售卖价格
  1952. $itemPrice = $productData[$productId]['price'] ?? 0;
  1953. //合计价格
  1954. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1955. }
  1956. //没有经纬度的客户运费直接返回空 ssh 20210612
  1957. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1958. util::success(['sedCost' => '']);
  1959. }
  1960. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1961. util::success(['sedCost' => $cost]);
  1962. }
  1963. $province = $get['province'] ?? '';
  1964. $city = $get['city'] ?? '';
  1965. $address = $get['address'] ?? '';
  1966. $floor = $get['floor'] ?? '';
  1967. $customName = $get['customName'] ?? '';
  1968. $customMobile = $get['customMobile'] ?? '';
  1969. $fullAddress = $province . $city . $address . $floor;
  1970. $sendTime = $get['sendTime'] ?? '';
  1971. $lat = $get['lat'] ?? '';
  1972. $lng = $get['long'] ?? '';
  1973. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1974. util::fail('请填写客户地址');
  1975. }
  1976. ini_set('date.timezone', 'Asia/Shanghai');
  1977. if (!empty($sendTime)) {
  1978. //配送时间不为空
  1979. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1980. $sendTimeInt = strtotime($sendTime);
  1981. $now = time();
  1982. $diff = $sendTimeInt - $now;
  1983. //因服务器写入时间,改为至少提前6分钟
  1984. if ($diff <= 360) {
  1985. util::fail('配送时间至少提前6分钟');
  1986. }
  1987. } else {
  1988. //默认立即发送
  1989. $sendTime = 0;
  1990. }
  1991. //更新订单表
  1992. $info = OrderService::getOrderInfo($orderId);
  1993. OrderClass::valid($info, $this->shopId);
  1994. if ($sendTime) {
  1995. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1996. } else {
  1997. $sendTime = '0000-00-00 00:00:00';
  1998. }
  1999. $expressAddInfo = [
  2000. 'customName' => $customName,
  2001. 'customMobile' => $customMobile,
  2002. 'province' => $province,
  2003. 'city' => $city,
  2004. 'address' => $address,
  2005. 'floor' => $floor,
  2006. 'lat' => $lat,
  2007. 'long' => $lng,
  2008. 'sendTime' => $sendTime,
  2009. ];
  2010. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  2011. //计算运费
  2012. $info['province'] = $province;
  2013. $info['city'] = $city;
  2014. $info['address'] = $address;
  2015. $info['floor'] = $floor;
  2016. $info['fullAddress'] = $fullAddress;
  2017. $info['lat'] = $lat;
  2018. $info['long'] = $lng;
  2019. $info['sendTime'] = $expressAddInfo['sendTime'];
  2020. $res = DadaExpressServices::queryDeliverFee($info);
  2021. util::success(['sedCost' => $res['fee']]);
  2022. }
  2023. //发快递和第三方配送 ssh 2021.1.24
  2024. public function actionThirdSend()
  2025. {
  2026. $get = Yii::$app->request->get();
  2027. $id = isset($get['id']) ? $get['id'] : 0;
  2028. $info = OrderService::getById($id, true);
  2029. OrderClass::valid($info->attributes, $this->shopId);
  2030. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  2031. util::fail('请填写客户地址');
  2032. }
  2033. $connection = Yii::$app->db;
  2034. $transaction = $connection->beginTransaction();
  2035. try {
  2036. $respond = OrderClass::thirdSend($info, $get);
  2037. $transaction->commit();
  2038. util::success($respond);
  2039. } catch (\Exception $exception) {
  2040. $transaction->rollBack();
  2041. Yii::info("发快递操作报错:" . $exception->getMessage());
  2042. util::fail('操作失败' . $exception->getMessage());
  2043. }
  2044. }
  2045. //确认送达 ssh 2021.1.24
  2046. public function actionReach()
  2047. {
  2048. $get = Yii::$app->request->get();
  2049. $id = isset($get['id']) ? $get['id'] : 0;
  2050. $info = OrderClass::getById($id, true);
  2051. OrderClass::valid($info->attributes, $this->shopId);
  2052. $connection = Yii::$app->db;
  2053. $transaction = $connection->beginTransaction();
  2054. try {
  2055. OrderService::reach($info);
  2056. $transaction->commit();
  2057. } catch (\Exception $exception) {
  2058. $transaction->rollBack();
  2059. Yii::info("送达操作报错:" . $exception->getMessage());
  2060. util::fail('操作失败');
  2061. }
  2062. util::complete();
  2063. }
  2064. //下单要用到的相关信息 ssh 2019.12.6
  2065. public function actionOrderRelate()
  2066. {
  2067. $regionTree = RegionService::tree();
  2068. $shop = $this->shop->attributes;
  2069. $freight = ['first' => 5, 'add' => 2];
  2070. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  2071. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  2072. util::success($out);
  2073. }
  2074. //客户欠款的订单 ssh 2021.2.4
  2075. public function actionDebtList()
  2076. {
  2077. $get = Yii::$app->request->get();
  2078. $id = $get['id'] ?? 0;
  2079. $info = CustomClass::getCustom($id);
  2080. CustomClass::valid($info, $this->shopId);
  2081. $mainId = $this->mainId;
  2082. $where = ['mainId' => $mainId, 'customId' => $id, 'debt' => 1];
  2083. $searchTime = $get['searchTime'] ?? '';
  2084. if (!empty($searchTime)) {
  2085. $startTime = $get['startTime'] ?? '';
  2086. $endTime = $get['endTime'] ?? '';
  2087. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  2088. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  2089. } else {
  2090. if ($mainId == 33447 && $id == 51031) {
  2091. util::fail('请选时间');
  2092. }
  2093. }
  2094. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'payTime']);
  2095. $result = ['customInfo' => $info, 'list' => $list];
  2096. util::success($result);
  2097. }
  2098. //更新打印次数
  2099. public function actionAddPrintNum()
  2100. {
  2101. $id = Yii::$app->request->get('id', 0);
  2102. $order = OrderClass::getById($id, true);
  2103. OrderClass::valid($order, $this->shopId);
  2104. $order->printNum += 1;
  2105. $order->save();
  2106. util::complete();
  2107. }
  2108. //打印订单 ssh 20210714
  2109. public function actionCloudPrintOrder()
  2110. {
  2111. $get = Yii::$app->request->get();
  2112. $id = $get['id'] ?? 0;
  2113. $showPrice = $get['showPrice'] ?? 1;
  2114. $order = OrderClass::getById($id, true);
  2115. OrderClass::valid($order, $this->shopId);
  2116. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  2117. util::fail('订单还没有付款');
  2118. }
  2119. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  2120. util::fail('订单已取消');
  2121. }
  2122. $ext = $this->shopExt;
  2123. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  2124. util::success(['hasNoPrint' => 1]);
  2125. }
  2126. OrderClass::onlinePrint($order, $showPrice);
  2127. $order->printNum += 1;
  2128. $order->save();
  2129. util::complete();
  2130. }
  2131. //订单确认完成 ssh 20210809
  2132. public function actionConfirmFinish()
  2133. {
  2134. $payWay = Yii::$app->request->get('payWay', -1);
  2135. $id = Yii::$app->request->get('id', 0);
  2136. $clearType = Yii::$app->request->get('clearType', 0);
  2137. $connection = Yii::$app->db;
  2138. $transaction = $connection->beginTransaction();
  2139. try {
  2140. $order = OrderClass::getById($id, true);
  2141. OrderClass::valid($order, $this->shopId);
  2142. $purchaseId = $order->purchaseId ?? 0;
  2143. $purchase = PurchaseClass::getById($purchaseId, true);
  2144. if (empty($purchase)) {
  2145. util::fail('没有采购信息');
  2146. }
  2147. if ($clearType == 1) {
  2148. //欠款
  2149. $payWay = dict::getDict('payWay', 'debtPay');
  2150. } elseif ($clearType == 2) {
  2151. //已收款
  2152. if ($payWay == -1) {
  2153. util::fail('请选择收款方式');
  2154. }
  2155. $shopAdmin = $this->shopAdmin;
  2156. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2157. util::fail('超管才能发起已收款');
  2158. }
  2159. } else {
  2160. util::fail('请选择结算方式');
  2161. }
  2162. //不需要打印
  2163. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  2164. $order->save();
  2165. //支付
  2166. PurchaseService::payAfter($purchase, $payWay);
  2167. OrderService::payAfter($order, $payWay);
  2168. //自己送
  2169. $info = OrderClass::getById($id, true);
  2170. OrderClass::selfSend($info);
  2171. //确认送达,并且不需要微信通知
  2172. Yii::$app->params['noNeedWxNotice'] = 1;
  2173. $info = OrderClass::getById($id, true);
  2174. OrderService::reach($info);
  2175. $transaction->commit();
  2176. util::complete('操作成功');
  2177. } catch (\Exception $exception) {
  2178. $transaction->rollBack();
  2179. Yii::info("确认完成订单报错:" . $exception->getMessage());
  2180. util::fail('操作失败');
  2181. }
  2182. }
  2183. //取消订单 ssh 20220110
  2184. public function actionCancel()
  2185. {
  2186. $shopAdmin = $this->shopAdmin;
  2187. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2188. util::fail('超管才能取消订单');
  2189. }
  2190. $id = Yii::$app->request->get('id');
  2191. $order = OrderClass::getById($id, true);
  2192. if ($order->orderType == 2) {
  2193. util::fail('客户下单,不能主动取消');
  2194. }
  2195. OrderClass::valid($order, $this->shopId);
  2196. OrderService::expire($order, true);
  2197. util::complete('已取消');
  2198. }
  2199. //获取收款语音播报地址 ssh 20211231
  2200. public function actionGetPayVoice()
  2201. {
  2202. $id = Yii::$app->request->get('id');
  2203. $order = OrderClass::getById($id, true);
  2204. $payWay = $order->payWay ?? 0;
  2205. $money = floatval($order->actPrice);
  2206. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  2207. $msg = $payment . '收款' . $money . '元';
  2208. $audio = baiduAip::transfer($msg, 4, 0);
  2209. //上传到oss
  2210. $file = time() . rand(10000, 999999) . '.mp3';
  2211. $filePath = 'tmp/arrival/money/' . $file;
  2212. oss::uploadTmpAudio($filePath, $audio);
  2213. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  2214. util::success(['url' => $url]);
  2215. }
  2216. //修改备注
  2217. public function actionModifyRemark()
  2218. {
  2219. $post = Yii::$app->request->post();
  2220. $id = $post['id'] ?? 0;
  2221. $remark = $post['remark'] ?? '';
  2222. $order = OrderClass::getById($id, true);
  2223. if (empty($order)) {
  2224. util::fail('没有找到订单');
  2225. }
  2226. if ($order->mainId != $this->mainId) {
  2227. util::fail('不是你的订单');
  2228. }
  2229. $cgId = $order->purchaseId ?? 0;
  2230. $cg = PurchaseClass::getById($cgId, true);
  2231. if (empty($cg)) {
  2232. util::fail('采购单没有找到');
  2233. }
  2234. $order->remark = $remark;
  2235. $order->save();
  2236. $cg->remark = $remark;
  2237. $cg->save();
  2238. util::complete('修改成功');
  2239. }
  2240. //修改订单的确认时间 ssh 20240511
  2241. public function actionModifyOrderConfirmTime()
  2242. {
  2243. $get = Yii::$app->request->get();
  2244. $id = $get['id'] ?? 0;
  2245. $date = $get['date'] ?? '';
  2246. if (empty($date)) {
  2247. util::fail('请选择日期');
  2248. }
  2249. $order = OrderClass::getById($id, true);
  2250. if (empty($order)) {
  2251. util::fail('没有找到订单');
  2252. }
  2253. if ($order->mainId != $this->mainId) {
  2254. util::fail('不是你的订单');
  2255. }
  2256. if ($order->payStatus == 0) {
  2257. util::fail('没有确认的订单');
  2258. }
  2259. $mainId = $this->mainId;
  2260. //超管或者约定的人可以修改日期
  2261. if (getenv('YII_ENV') == 'production') {
  2262. if (in_array($mainId, [23390])) {
  2263. if (!in_array($this->adminId, [24586, 23960, 24043])) {
  2264. util::fail('你不能修改哦');
  2265. }
  2266. }
  2267. } else {
  2268. if (in_array($mainId, [644])) {
  2269. if (!in_array($this->adminId, [919])) {
  2270. }
  2271. }
  2272. }
  2273. $payTime = $order->payTime;
  2274. $time = strtotime($payTime);
  2275. $after = date("H:i:s", $time);
  2276. $new = $date . ' ' . $after;
  2277. $cgId = $order->purchaseId ?? 0;
  2278. $cg = PurchaseClass::getById($cgId, true);
  2279. if (empty($cg)) {
  2280. util::fail('没有找到订单信息');
  2281. }
  2282. if (strtotime($new) > time()) {
  2283. util::fail('不能修改成未来时间');
  2284. }
  2285. $order->payTime = $new;
  2286. $order->save();
  2287. $cg->payTime = $new;
  2288. $cg->save();
  2289. //有修改账单日期需要更新到欠款变动明细,财务好对账,多个地方要同步修改,关键词to_change_custom_debt_pay_time
  2290. CustomDebtChangeClass::updateByCondition(['capitalType' => 10, 'relateId' => $id], ['payTime' => $new]);
  2291. util::complete('修改成功');
  2292. }
  2293. //应收款统计 ssh 20240528
  2294. public function actionAccountList()
  2295. {
  2296. $get = Yii::$app->request->get();
  2297. $mainId = $this->mainId;
  2298. $export = $get['export'] ?? 0;
  2299. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2300. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2301. $startTime = $get['startTime'] ?? '';
  2302. $endTime = $get['endTime'] ?? '';
  2303. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2304. $start = $period['startTime'];
  2305. $end = $period['endTime'];
  2306. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  2307. $currentStartDate = date('Y-m-d', strtotime($start));
  2308. $currentEndDate = date('Y-m-d', strtotime($end));
  2309. $currentStartTime = $currentStartDate . ' 00:00:00';
  2310. $currentEndTime = $currentEndDate . ' 23:59:59';
  2311. $where = ['mainId' => $mainId];
  2312. if ($debt > -1) {
  2313. $where['debt'] = $debt;
  2314. }
  2315. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2316. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2317. $list = [];
  2318. $totalAmount = 0;
  2319. if (!empty($orderList)) {
  2320. foreach ($orderList as $orderInfo) {
  2321. $actPrice = $orderInfo['actPrice'] ?? 0;
  2322. $customId = $orderInfo['customId'] ?? 0;
  2323. $status = $orderInfo['status'] ?? 0;
  2324. $book = $orderInfo['book'] ?? 0;
  2325. if ($status == 1 || $status == 5) {
  2326. continue;
  2327. }
  2328. if ($book == 1 && $status == 2) {
  2329. continue;
  2330. }
  2331. if (isset($list[$customId])) {
  2332. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  2333. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2334. } else {
  2335. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2336. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  2337. }
  2338. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  2339. }
  2340. $list = array_values($list);
  2341. }
  2342. if ($export == 1) {
  2343. if (empty($list)) {
  2344. util::fail('没有数据需要导出');
  2345. }
  2346. ini_set('memory_limit', '2045M');
  2347. set_time_limit(0);
  2348. OrderClass::exportAccountList($list, $mainId);
  2349. util::stop();
  2350. }
  2351. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  2352. }
  2353. //应收款统计 ssh 20240528
  2354. public function actionPastList()
  2355. {
  2356. $get = Yii::$app->request->get();
  2357. $export = $get['export'] ?? 0;
  2358. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2359. $startTime = $get['startTime'] ?? '';
  2360. $endTime = $get['endTime'] ?? '';
  2361. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2362. $end = $period['endTime'];
  2363. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  2364. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end), 86400));
  2365. $totalAmount = 0;
  2366. if (!empty($customList)) {
  2367. foreach ($customList as $key => $custom) {
  2368. $customId = $custom['id'] ?? 0;
  2369. $change = CustomDebtChangeClass::getByCondition(['customId' => $customId, 'addTime<' => $currentDate], true, 'addTime DESC');
  2370. $amount = $change->balance ?? 0;
  2371. $totalAmount = bcadd($totalAmount, $amount, 2);
  2372. $customList[$key]['currentDebAmount'] = $amount;
  2373. }
  2374. $customList = array_values($customList);
  2375. }
  2376. if ($export == 1) {
  2377. $mainId = $this->mainId;
  2378. if (empty($customList)) {
  2379. util::fail('没有数据需要导出');
  2380. }
  2381. ini_set('memory_limit', '2045M');
  2382. set_time_limit(0);
  2383. OrderClass::exportPastList($customList, $mainId);
  2384. util::stop();
  2385. }
  2386. util::success(['list' => $customList, 'totalAmount' => $totalAmount]);
  2387. }
  2388. //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
  2389. public function actionYj()
  2390. {
  2391. $get = Yii::$app->request->get();
  2392. $mainId = $this->mainId;
  2393. $export = $get['export'] ?? 0;
  2394. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2395. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2396. $startTime = $get['startTime'] ?? '';
  2397. $endTime = $get['endTime'] ?? '';
  2398. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2399. $start = $period['startTime'];
  2400. $end = $period['endTime'];
  2401. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
  2402. $currentStartDate = date('Y-m-d', strtotime($start));
  2403. $currentEndDate = date('Y-m-d', strtotime($end));
  2404. $currentStartTime = $currentStartDate . ' 00:00:00';
  2405. $currentEndTime = $currentEndDate . ' 23:59:59';
  2406. $where = ['mainId' => $mainId];
  2407. if ($debt > -1) {
  2408. $where['debt'] = $debt;
  2409. }
  2410. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2411. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2412. $list = [];
  2413. $totalActPrice = 0;
  2414. $totalOrderPrice = 0;
  2415. $totalCarton = 0;
  2416. $totalCartonNum = 0;
  2417. $totalPack = 0;
  2418. $totalFreight = 0;
  2419. $totalTkPrice = 0;
  2420. //增加项
  2421. $totalOnlyTkPrice = 0;
  2422. $totalNum = 0;
  2423. if (!empty($orderList)) {
  2424. foreach ($orderList as $orderInfo) {
  2425. $actPrice = $orderInfo['actPrice'] ?? 0;
  2426. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  2427. $customId = $orderInfo['customId'] ?? 0;
  2428. $status = $orderInfo['status'] ?? 0;
  2429. $book = $orderInfo['book'] ?? 0;
  2430. $orderSn = $orderInfo['orderSn'] ?? '';
  2431. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  2432. if ($status == 1 || $status == 5) {
  2433. continue;
  2434. }
  2435. if ($book == 1 && $status == 2) {
  2436. continue;
  2437. }
  2438. $carton = 0;
  2439. $cartonNum = 0;
  2440. $pack = 0;
  2441. $freight = 0;
  2442. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  2443. if ($actPrice > 0) {
  2444. if (!empty($orderItemList)) {
  2445. foreach ($orderItemList as $orderItem) {
  2446. $num = $orderItem['xhNum'] ?? 0;
  2447. $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
  2448. $refundNum = $orderItem['refundNum'] ?? 0;
  2449. $classId = $orderItem['classId'] ?? 0;
  2450. if (getenv('YII_ENV') == 'production') {
  2451. //小向算打包纸箱费用
  2452. if ($mainId == 23390) {
  2453. $remainNum = bcsub($num, $refundNum);
  2454. $amount = bcmul($remainNum, $unitPrice, 2);
  2455. if ($classId == 72106) {
  2456. $carton = bcadd($carton, $amount, 2);
  2457. $cartonNum = bcadd($cartonNum, $remainNum);
  2458. }
  2459. if ($classId == 72108) {
  2460. $pack = bcadd($pack, $amount, 2);
  2461. }
  2462. if ($classId == 73118) {
  2463. $freight = bcadd($freight, $amount, 2);
  2464. }
  2465. }
  2466. //花大苪
  2467. if ($mainId == 8164) {
  2468. $remainNum = bcsub($num, $refundNum);
  2469. $amount = bcmul($remainNum, $unitPrice, 2);
  2470. if ($classId == 90497) {
  2471. $carton = bcadd($carton, $amount, 2);
  2472. $cartonNum = bcadd($cartonNum, $remainNum);
  2473. }
  2474. if ($classId == 90501) {
  2475. $freight = bcadd($freight, $amount, 2);
  2476. }
  2477. }
  2478. //石头花艺
  2479. if ($mainId == 50) {
  2480. $remainNum = bcsub($num, $refundNum);
  2481. $amount = bcmul($remainNum, $unitPrice, 2);
  2482. if ($classId == 71495) {
  2483. $carton = bcadd($carton, $amount, 2);
  2484. $cartonNum = bcadd($cartonNum, $remainNum);
  2485. }
  2486. if ($classId == 91009) {
  2487. $freight = bcadd($freight, $amount, 2);
  2488. }
  2489. }
  2490. }
  2491. }
  2492. }
  2493. }
  2494. //增加项
  2495. if ($tkPrice > 0) {
  2496. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  2497. if (!empty($refundList)) {
  2498. foreach ($refundList as $refundInfo) {
  2499. if ($refundInfo->status == 1) {
  2500. if ($refundInfo->refundType == 2) {
  2501. $refundPrice = $refundInfo->refundPrice ?? 0;
  2502. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  2503. }
  2504. }
  2505. }
  2506. }
  2507. }
  2508. $totalCarton = bcadd($totalCarton, $carton, 2);
  2509. $totalCartonNum = bcadd($totalCartonNum, $cartonNum);
  2510. $totalPack = bcadd($totalPack, $pack, 2);
  2511. $totalFreight = bcadd($totalFreight, $freight, 2);
  2512. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  2513. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  2514. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  2515. $totalNum++;
  2516. if (isset($list[$customId])) {
  2517. $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
  2518. $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
  2519. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2520. $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton, 2);
  2521. $list[$customId]['cartonNum'] = bcadd($list[$customId]['cartonNum'], $cartonNum);
  2522. $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $pack, 2);
  2523. $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $freight, 2);
  2524. $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice, 2);
  2525. } else {
  2526. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2527. $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
  2528. $list[$customId] = [
  2529. 'id' => $customId,
  2530. 'name' => $name,
  2531. 'mobile' => $mobile,
  2532. 'orderPrice' => $orderPrice,
  2533. 'actPrice' => $actPrice,
  2534. 'num' => 1,
  2535. 'carton' => $carton,
  2536. 'cartonNum' => $cartonNum,
  2537. 'pack' => $pack,
  2538. 'freight' => $freight,
  2539. 'tkPrice' => $tkPrice,
  2540. ];
  2541. }
  2542. }
  2543. foreach ($customList as $key => $custom) {
  2544. $customId = $custom['id'] ?? 0;
  2545. if (isset($list[$customId]) == false) {
  2546. $list[$customId] = [
  2547. 'id' => $customId,
  2548. 'name' => $custom['name'],
  2549. 'mobile' => $custom['mobile'],
  2550. 'actPrice' => 0,
  2551. 'num' => 0,
  2552. 'carton' => 0,
  2553. 'pack' => 0,
  2554. 'freight' => 0,
  2555. 'tkPrice' => 0,
  2556. 'orderPrice' => 0,
  2557. ];
  2558. }
  2559. }
  2560. $list = array_values($list);
  2561. }
  2562. if ($export == 1) {
  2563. if (empty($list)) {
  2564. util::fail('没有数据需要导出');
  2565. }
  2566. ini_set('memory_limit', '2045M');
  2567. set_time_limit(0);
  2568. OrderClass::exportYj($list, $mainId);
  2569. util::stop();
  2570. }
  2571. util::success([
  2572. 'list' => $list,
  2573. 'totalActPrice' => $totalActPrice,
  2574. 'totalOrderPrice' => $totalOrderPrice,
  2575. 'totalCarton' => $totalCarton,
  2576. 'totalCartonNum' => $totalCartonNum,
  2577. 'totalNum' => $totalNum,
  2578. 'totalPack' => $totalPack,
  2579. 'totalFreight' => $totalFreight,
  2580. 'totalTkPrice' => $totalTkPrice,
  2581. //增加项
  2582. 'totalOnlyTkPrice' => $totalOnlyTkPrice,
  2583. ]);
  2584. }
  2585. //修改配送人 ssh 20240824
  2586. public function actionChangeSendStaff()
  2587. {
  2588. $staff = $this->shopAdmin;
  2589. if (isset($staff->finance) == false || $staff->finance == 0) {
  2590. util::fail('请有财务权限的人修改');
  2591. }
  2592. $get = Yii::$app->request->get();
  2593. $staffId = $get['staffId'] ?? 0;
  2594. $orderId = $get['orderId'] ?? 0;
  2595. $order = OrderClass::getById($orderId, true);
  2596. if (empty($order)) {
  2597. util::fail('没有找到订单');
  2598. }
  2599. if ($order->mainId != $this->mainId) {
  2600. util::fail('不是你的');
  2601. }
  2602. $staff = ShopAdminClass::getById($staffId, true);
  2603. if (empty($staff)) {
  2604. util::fail('没有找到员工');
  2605. }
  2606. if ($staff->mainId != $this->mainId) {
  2607. util::fail('不是你的员工');
  2608. }
  2609. $staffName = $staff->name ?? '';
  2610. $order->sendStaffId = $staffId;
  2611. $order->sendStaffName = $staffName;
  2612. $order->save();
  2613. util::complete('修改成功');
  2614. }
  2615. //导入开单 ssh 20241126
  2616. public function actionImportCreate()
  2617. {
  2618. ini_set('memory_limit', '2045M');
  2619. set_time_limit(0);
  2620. $connection = Yii::$app->db;
  2621. $transaction = $connection->beginTransaction();
  2622. try {
  2623. $get = Yii::$app->request->get();
  2624. $customId = $get['id'] ?? '';
  2625. $customRes = CustomClass::getById($customId, true);
  2626. if (empty($customRes)) {
  2627. util::fail('没有找到客户');
  2628. }
  2629. if ($customRes->ownMainId != $this->mainId) {
  2630. util::fail('不是你的客户');
  2631. }
  2632. if (isset($customRes->mainId) && !empty($customRes->mainId) && $customRes->mainId == $customRes->ownMainId) {
  2633. util::fail('不能给自己开单');
  2634. }
  2635. $file = $_FILES['file'];
  2636. if (!is_uploaded_file($file['tmp_name'])) {
  2637. util::fail('please upload img');
  2638. }
  2639. $mainId = $this->mainId;
  2640. $sjId = $this->sjId;
  2641. $shopId = $this->shopId;
  2642. $month = date("Ym");
  2643. $date = date("d");
  2644. $path = dirUtil::getImgUploadDir() . "/{$mainId}/kd/{$shopId}/{$month}/{$date}/";
  2645. if (!file_exists($path)) {
  2646. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  2647. mkdir($path, 0700, true);
  2648. }
  2649. $preFileName = stringUtil::uniqueFileName();
  2650. $newFile = $preFileName . ".xls";
  2651. $fullPathFile = $path . $newFile;
  2652. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  2653. $arr = [];
  2654. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2655. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  2656. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  2657. // 获取活动工作表
  2658. $worksheet = $spreadsheet->getActiveSheet();
  2659. // 遍历每一行
  2660. foreach ($worksheet->getRowIterator() as $key => $row) {
  2661. $cellIterator = $row->getCellIterator();
  2662. // 这里设置为迭代所有单元格,包括空单元格
  2663. $cellIterator->setIterateOnlyExistingCells(FALSE);
  2664. // 遍历每列
  2665. $rowData = [];
  2666. foreach ($cellIterator as $cell) {
  2667. $option = $cell->getValue();
  2668. $rowData[] = trim($option);
  2669. }
  2670. $arr[] = $rowData;
  2671. }
  2672. array_shift($arr);
  2673. $productIds = [];
  2674. foreach ($arr as $k => $v) {
  2675. $productId = $v[0] ?? 0;
  2676. $productId = trim($productId);
  2677. if (is_numeric($productId) && $productId > 0) {
  2678. $productIds[] = $productId;
  2679. }
  2680. }
  2681. if (empty($productIds)) {
  2682. util::fail('没有识别出花材');
  2683. }
  2684. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  2685. if (empty($productInfo)) {
  2686. util::fail('没有找到有效花材');
  2687. }
  2688. $mat = [];
  2689. foreach ($arr as $k => $v) {
  2690. $productId = $v[0] ?? 0;
  2691. $productId = trim($productId);
  2692. $num = $v[2] ?? 0;
  2693. $num = trim($num);
  2694. $unitPrice = $v[3] ?? 0;
  2695. $unitPrice = trim($unitPrice);
  2696. $remark = $v['5'] ?? '';
  2697. $remark = trim($remark);
  2698. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  2699. $product = $productInfo[$productId] ?? [];
  2700. $ptItemId = $product['itemId'] ?? 0;
  2701. $mat[] = [
  2702. 'productId' => $productId,
  2703. 'bigNum' => $num,
  2704. 'itemId' => $ptItemId,
  2705. 'smallNum' => 0,
  2706. 'price' => $unitPrice,
  2707. 'remark' => $remark,
  2708. ];
  2709. }
  2710. }
  2711. $modifyPrice = 0;
  2712. foreach ($mat as $ma) {
  2713. $cNum = $ma['bigNum'] ?? 0;
  2714. $cPrice = $ma['price'] ?? 0;
  2715. $cTotal = bcmul($cNum, $cPrice, 2);
  2716. $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
  2717. }
  2718. $customName = $customRes->name ?? '';
  2719. $customMobile = $customRes->mobile ?? '';
  2720. $customPy = $customRes->py ?? '';
  2721. $ghsId = $customRes->ghsId ?? 0;
  2722. $hasPay = 2;
  2723. $custom = CustomClass::getCustom($customId);
  2724. $post = [];
  2725. $post['modifyPrice'] = $modifyPrice;
  2726. $post['shopId'] = $shopId;
  2727. $post['sendType'] = 0;
  2728. $post['transType'] = 0;
  2729. $post['sendSide'] = 0;
  2730. $post['sendCost'] = 0;
  2731. $post['packCost'] = 0;
  2732. $post['customId'] = $customId;
  2733. $post['customName'] = $customName;
  2734. $post['payWay'] = 0;
  2735. $post['needPrint'] = 2;
  2736. $post['hasPay'] = 2;
  2737. $post['product'] = $mat;
  2738. $post['deadline'] = date("Y-m-d H:i:s", time() + 86400);
  2739. $post['debt'] = 1;
  2740. $post['mainId'] = $mainId;
  2741. $post['fromType'] = 1;
  2742. $post['expressId'] = 0;
  2743. $post['sjId'] = $sjId;
  2744. $staff = $this->shopAdmin;
  2745. $staffId = $staff->id ?? 0;
  2746. $staffName = $staff->name ?? '';
  2747. $post['shopAdminId'] = $staffId;
  2748. $post['shopAdminName'] = $staffName;
  2749. $post['getStaffId'] = $staffId;
  2750. $post['getStaffName'] = $staffName;
  2751. $post['customMobile'] = $customMobile;
  2752. $post['customNamePy'] = $customPy;
  2753. $post['customAvatar'] = '';
  2754. $post['newVersion'] = 1;
  2755. $post['book'] = 1;
  2756. $post['wlName'] = '';
  2757. $post['dealPrice'] = 1;
  2758. $post['ghsId'] = $ghsId;
  2759. $shop = $this->shop;
  2760. $bookSn = $shop->bookSn ?? 0;
  2761. $post['bookSn'] = $bookSn;
  2762. //多处有用到此方法,需要同步修改,搜索关键词create_new_order
  2763. OrderService::createNewOrder($post, $custom, $hasPay);
  2764. $transaction->commit();
  2765. util::complete('提交成功');
  2766. } else {
  2767. util::fail('上传失败了,出错了哦');
  2768. }
  2769. } catch (\Exception $e) {
  2770. $transaction->rollBack();
  2771. Yii::info("导入失败了," . $e->getMessage());
  2772. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  2773. $msg = $e->getMessage();
  2774. util::fail('导入失败:' . $msg);
  2775. }
  2776. }
  2777. //打印发物流用和标签 ssh 20250312
  2778. public function actionPrintWlLabel()
  2779. {
  2780. $get = Yii::$app->request->get();
  2781. $id = $get['id'] ?? 0;
  2782. $order = OrderClass::getById($id, true);
  2783. if (empty($order)) {
  2784. util::fail('没有找到订单');
  2785. }
  2786. $ext = $this->shopExt;
  2787. $shop = $this->shop;
  2788. OrderClass::printLogisticsLabel($order, $shop, $ext);
  2789. util::complete('打印成功');
  2790. }
  2791. //修改地址 ssh 20251123
  2792. public function actionModifyAddress()
  2793. {
  2794. $post = Yii::$app->request->post();
  2795. $id = $post['id'] ?? 0;
  2796. $order = OrderClass::getById($id, true);
  2797. if (empty($order)) {
  2798. util::fail('没有找到订单');
  2799. }
  2800. if ($order->mainId != $this->mainId) {
  2801. util::fail('不是你的订单,不能修改地址');
  2802. }
  2803. if ($order->status == 3) {
  2804. util::fail('订单已经在配送了,不能修改地址');
  2805. }
  2806. if ($order->status == 4) {
  2807. util::fail('订单已完成,不能修改地址');
  2808. }
  2809. $province = $post['province'] ?? '';
  2810. $city = $post['city'] ?? '';
  2811. $dist = $post['dist'] ?? '';
  2812. $address = $post['address'] ?? '';
  2813. $floor = $post['floor'] ?? '';
  2814. $fullAddress = $city . $dist . $address . $floor;
  2815. $lat = $post['lat'] ?? '';
  2816. $long = $post['long'] ?? '';
  2817. $showAddress = $post['showAddress'] ?? '';
  2818. $order->province = $province;
  2819. $order->city = $city;
  2820. $order->dist = $dist;
  2821. $order->address = $address;
  2822. $order->floor = $floor;
  2823. $order->showAddress = $showAddress;
  2824. $order->fullAddress = $fullAddress;
  2825. $order->lat = $lat;
  2826. $order->long = $long;
  2827. $order->save();
  2828. if ($post['syncDefaultAddress'] == 1) {
  2829. $customId = $order->customId ?? 0;
  2830. $custom = CustomClass::getById($customId, true);
  2831. if (!empty($custom)) {
  2832. $custom->province = $province;
  2833. $custom->city = $city;
  2834. $custom->dist = $dist;
  2835. $custom->address = $address;
  2836. $custom->floor = $floor;
  2837. $custom->showAddress = $showAddress;
  2838. $custom->fullAddress = $fullAddress;
  2839. $custom->lat = $lat;
  2840. $custom->long = $long;
  2841. $custom->save();
  2842. }
  2843. }
  2844. util::complete('修改成功');
  2845. }
  2846. }