OrderController.php 97 KB

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