OrderController.php 79 KB

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