OrderController.php 98 KB

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