OrderController.php 169 KB

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