OrderController.php 84 KB

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