OrderController.php 136 KB

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