OrderController.php 135 KB

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