OrderController.php 127 KB

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