OrderController.php 99 KB

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