OrderController.php 137 KB

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