OrderController.php 136 KB

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