OrderController.php 179 KB

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