OrderController.php 84 KB

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