OrderController.php 137 KB

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