TestController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantService;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\message\classes\InformAdminClass;
  7. use bizHd\order\services\OrderService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizGhs\express\services\MiniExpressService;
  10. use common\components\dict;
  11. use common\components\lakala\Lakala;
  12. use common\components\miniUtil;
  13. use common\components\orderSn;
  14. use common\components\wxUtil;
  15. use Yii;
  16. use common\components\util;
  17. class TestController extends BaseController
  18. {
  19. public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
  20. public function actionAliRun()
  21. {
  22. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  23. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  24. $arr = [
  25. ['name' => '国兰花尚', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  26. //['name' => '花掌柜', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
  27. ['name' => '纯彩花艺', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
  28. ['name' => '集美天天鲜花', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
  29. ];
  30. $new = [];
  31. foreach ($arr as $item) {
  32. $wx = $item['wx'];
  33. $zfb = $item['zfb'];
  34. $name = $item['name'];
  35. $merchantNo = $item['merchantNo'];
  36. $group = [];
  37. foreach ($wx as $oneWx) {
  38. $params = [
  39. 'appid' => 'OP00002119',
  40. 'serial_no' => '018b08cfddbd',
  41. 'merchant_no' => $merchantNo,
  42. 'term_no' => 'C6337694',
  43. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  44. 'lklCertificatePath' => $lklCertificatePath,
  45. ];
  46. $data = [
  47. 'subMerchantId' => $oneWx,
  48. 'tradeMode' => 'WECHAT',
  49. ];
  50. $laResource = new Lakala($params);
  51. $response = $laResource->openStateQuery($data);
  52. $statusName = '出错了';
  53. if ($response['retCode'] == '000000') {
  54. $checkResult = $response['respData']['checkResult'] ?? '';
  55. $statusName = '未确认';
  56. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
  57. $statusName = '已确认';
  58. }
  59. }
  60. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  61. }
  62. $params = [
  63. 'appid' => 'OP00002119',
  64. 'serial_no' => '018b08cfddbd',
  65. 'merchant_no' => $merchantNo,
  66. 'term_no' => 'C6337694',
  67. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  68. 'lklCertificatePath' => $lklCertificatePath,
  69. ];
  70. $data = [
  71. 'subMerchantId' => $zfb,
  72. 'tradeMode' => 'ALIPAY',
  73. ];
  74. $laResource = new Lakala($params);
  75. $response = $laResource->openStateQuery($data);
  76. $statusName = '出错了';
  77. if ($response['retCode'] == '000000') {
  78. $checkResult = $response['respData']['checkResult'] ?? '';
  79. $statusName = '未确认';
  80. if ($checkResult == 'AUTHORIZED') {
  81. $statusName = '已确认';
  82. }
  83. }
  84. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  85. $new[] = ['name' => $name, 'status' => $group];
  86. }
  87. print_r($new);
  88. }
  89. public function actionAliRun2()
  90. {
  91. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  92. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  93. $params = [
  94. 'appid' => 'OP00002119',
  95. 'serial_no' => '018b08cfddbd',
  96. 'merchant_no' => '82240505992000N',
  97. 'term_no' => 'C6337694',
  98. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  99. 'lklCertificatePath' => $lklCertificatePath,
  100. ];
  101. $outTradeNo = orderSn::getPurchaseSn();
  102. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  103. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  104. $aliParams = [
  105. 'orderSn' => $outTradeNo,
  106. 'amount' => 0.16,
  107. 'capitalType' => $currentCapitalType,
  108. 'notifyUrl' => $notifyUrl,
  109. ];
  110. $laResource = new Lakala($params);
  111. $response = $laResource->driveAliPay($aliParams);
  112. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  113. echo '<pre>';
  114. echo "下单成功<br/>";
  115. print_r($response);
  116. } else {
  117. echo '<pre>';
  118. echo "下单失败<br/>";
  119. print_r($response);
  120. }
  121. }
  122. public function actionAliRun3()
  123. {
  124. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  125. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  126. $params = [
  127. 'appid' => 'OP00002119',
  128. 'serial_no' => '018b08cfddbd',
  129. 'merchant_no' => '82240505992000N',
  130. 'term_no' => 'C6337694',
  131. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  132. 'lklCertificatePath' => $lklCertificatePath,
  133. ];
  134. $laResource = new Lakala($params);
  135. $outTradeNo = orderSn::getPurchaseSn();
  136. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  137. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  138. $wxParams = [
  139. 'orderSn' => $outTradeNo,
  140. 'amount' => 0.16,
  141. 'capitalType' => $currentCapitalType,
  142. 'notifyUrl' => $notifyUrl,
  143. ];
  144. $response = $laResource->driveWxPay($wxParams);
  145. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  146. echo '<pre>';
  147. echo "下单成功<br/>";
  148. print_r($response);
  149. } else {
  150. echo '<pre>';
  151. echo "下单失败<br/>";
  152. print_r($response);
  153. }
  154. }
  155. //dada 城市code
  156. public function actionDadaCityCode()
  157. {
  158. $res = dada::getCityCode(0);
  159. util::success($res);
  160. }
  161. //理由
  162. public function actionDadaReasons()
  163. {
  164. $res = dada::getCancelReason(0);
  165. util::success($res);
  166. }
  167. //达达 :下单
  168. public function actionDadaAddOrder()
  169. {
  170. $orderSn = 'XSD_CS26316851';
  171. $orderInfo = OrderClass::getByOrderSn($orderSn);
  172. $res = DadaExpressServices::addOrder($orderInfo);
  173. util::success($res);
  174. }
  175. //重发快递
  176. public function actionDadaReAdd()
  177. {
  178. $orderSn = 'XSD_CS26316851';
  179. $orderInfo = OrderClass::getByOrderSn($orderSn);
  180. $res = DadaExpressServices::reAddOrder($orderInfo);
  181. util::success($res);
  182. }
  183. //达达状态查询
  184. public function actionDadaOrderStatus()
  185. {
  186. $orderSn = 'XSD_CS26316851';
  187. $res = DadaExpressServices::statusOrder($orderSn);
  188. util::success($res);
  189. }
  190. //达达取消下单
  191. public function actionDadaCancelOrder()
  192. {
  193. $orderSn = 'XSD_CS26316851';
  194. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  195. util::success($res);
  196. }
  197. //获取已支持的配送公司列表接口
  198. public function actionGetAllDelivery()
  199. {
  200. $data = MiniExpressService::getAllImmeDelivery();
  201. util::success($data);
  202. }
  203. //即时配送
  204. /*
  205. * Array
  206. (
  207. [resultcode] => 0
  208. [resultmsg] => OK
  209. [shop_list] => Array
  210. (
  211. [0] => Array
  212. (
  213. [shopid] => 1588714266
  214. [delivery_id] => SFTC
  215. [audit_result] => 0
  216. [create_time] => 1612172838
  217. [remark] =>
  218. [delivery_name] => 顺丰同城急送
  219. )
  220. )
  221. )
  222. */
  223. public function actionGetBindAccount()
  224. {
  225. $merchant = WxOpenClass::getGhsWxInfo();
  226. $isOpen = 2;
  227. $r = miniUtil::getBindAccount($merchant, $isOpen);
  228. dd($r);
  229. }
  230. //下单 (沙箱)
  231. /**
  232. * Array
  233. * (
  234. * [resultcode] => 0
  235. * [resultmsg] => ok
  236. * [fee] => 10
  237. * [waybill_id] => test_shop_id1612365974_waybillid
  238. * [order_status] => 101
  239. * [dispatch_duration] => 300
  240. * )
  241. */
  242. public function actionCreateWaybill()
  243. {
  244. $merchant = WxOpenClass::getGhsWxInfo();
  245. $isOpen = 2;
  246. $shopId = 'test_shop_id';
  247. $shopOrderId = 'test_shop_id' . time();
  248. $appSecret = 'test_app_secrect';
  249. $data = [
  250. 'shopid' => $shopId,
  251. 'shop_order_id' => $shopOrderId,
  252. 'shop_no' => '1',
  253. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  254. 'delivery_id' => "TEST",
  255. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  256. 'sender' => [
  257. 'name' => 'test',
  258. 'city' => '厦门市',
  259. 'address' => '思明区',
  260. 'address_detail' => '软件园二期',
  261. 'phone' => '19959271111',
  262. 'lng' => 118.134343,
  263. 'lat' => 24.483566,
  264. 'coordinate_type' => 0,
  265. ],
  266. 'receiver' => [
  267. 'name' => 'test',
  268. 'city' => '厦门市',
  269. 'address' => '思明区',
  270. 'address_detail' => '软件园二期',
  271. 'phone' => '19959271111',
  272. 'lng' => 118.134343,
  273. 'lat' => 24.493566,
  274. 'coordinate_type' => 0,
  275. ],
  276. 'cargo' => [
  277. 'goods_value' => 1,
  278. 'goods_weight' => 0.1,
  279. 'cargo_first_class' => '鲜花',
  280. 'cargo_second_class' => '鲜花',
  281. ],
  282. 'order_info' => [
  283. 'order_type' => 0,
  284. ],
  285. 'shop' => [
  286. 'wxa_path' => '/shop',
  287. 'img_url' => 'http://www.baidu.com/test.png',
  288. 'goods_name' => 'test',
  289. 'goods_count' => 1,
  290. ],
  291. ];
  292. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  293. dd($r);
  294. }
  295. //获取运单数据
  296. /**
  297. * Array
  298. * (
  299. * [resultcode] => 0
  300. * [resultmsg] => ok
  301. * [order_status] => 101
  302. * [agent_info] => Array
  303. * (
  304. * )
  305. *
  306. * [waybill_id] => test_shop_id1612365974_waybillid
  307. * [rider_name] =>
  308. * [rider_phone] =>
  309. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  310. * )
  311. */
  312. public function actionGetOrder()
  313. {
  314. $shopId = 'test_shop_id';
  315. $shopOrderId = 'test_shop_id1612365974';
  316. $appSecret = 'test_app_secrect';
  317. $merchant = WxOpenClass::getGhsWxInfo();
  318. $isOpen = 2;
  319. $data = [
  320. 'shopid' => $shopId,
  321. 'shop_order_id' => $shopOrderId,
  322. 'shop_no' => '1',
  323. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  324. ];
  325. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  326. dd($r);
  327. }
  328. //沙盒 更新快递状态
  329. public function actionMockUpdateOrder()
  330. {
  331. $merchant = WxOpenClass::getGhsWxInfo();
  332. $isOpen = 2;
  333. /**
  334. * {
  335. * "shopid": "test_shop_id",
  336. * "shop_order_id": "xxxxxxxxxxx",
  337. * "waybill_id": "xxxxxxxxxxxxx",
  338. * "action_time": 12345678,
  339. * "order_status": 101,
  340. * "action_msg": "",
  341. * }
  342. */
  343. $shopId = 'test_shop_id';
  344. $shopOrderId = 'test_shop_id1612365974';
  345. $data = [
  346. 'shop_order_id' => $shopOrderId,
  347. "shopid" => $shopId,
  348. "action_time" => time(),
  349. "order_status" => 302,
  350. 'action_msg' => '状态变更',
  351. ];
  352. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  353. dd($r);
  354. }
  355. public function actionTest()
  356. {
  357. }
  358. //新增订单
  359. public function actionAddOrder()
  360. {
  361. $dada = Yii::getAlias("@vendor/dada/");
  362. require_once $dada . 'api/addOrderApi.php';
  363. require_once $dada . 'client/dadaRequestClient.php';
  364. require_once $dada . 'client/dadaResponse.php';
  365. require_once $dada . 'config/config.php';
  366. require_once $dada . 'model/orderModel.php';
  367. // isOnline 判断是否是测试环境,会有不同的域名等
  368. $isOnline = false;
  369. $sourceId = 1000000;
  370. // 初始化一个config
  371. $config = new \Config($sourceId, $isOnline);
  372. $orderModel = new \OrderModel();
  373. $orderModel->setShopNo('11047059');
  374. $orderModel->setOriginId('2018091100000002');
  375. $orderModel->setCityCode('021');
  376. $orderModel->setCargoPrice(10);
  377. $orderModel->setIsPrepay(0);
  378. $orderModel->setReceiverName('测试达达');
  379. $orderModel->setReceiverAddress('上海市崇明岛');
  380. $orderModel->setReceiverLat(31.63);
  381. $orderModel->setReceiverLng(121.41);
  382. $orderModel->setReceiverPhone('18588888888');
  383. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  384. // api主要有2个参数,一个是url, 一个是业务参数
  385. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  386. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  387. $resp = $dada_client->makeRequest();
  388. echo json_encode($resp);
  389. }
  390. //订单详情查询
  391. public function actionOrderQuery()
  392. {
  393. $dada = Yii::getAlias("@vendor/dada/");
  394. require_once $dada . 'api/OrderQueryApi.php';
  395. require_once $dada . 'client/dadaRequestClient.php';
  396. require_once $dada . 'client/dadaResponse.php';
  397. require_once $dada . 'config/config.php';
  398. require_once $dada . 'model/orderModel.php';
  399. // isOnline 判断是否是测试环境,会有不同的域名等
  400. $isOnline = false;
  401. $sourceId = 1000000;
  402. // 初始化一个config
  403. $config = new \Config($sourceId, $isOnline);
  404. $orderModel = new \OrderModel();
  405. $orderModel->setOrderId('2018091100000002');
  406. // api主要有2个参数,一个是url, 一个是业务参数
  407. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  408. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  409. $resp = $dada_client->makeRequest();
  410. echo json_encode($resp);
  411. }
  412. public function actionFocus()
  413. {
  414. $name = '花卉宝';
  415. if (getenv('YII_ENV') == 'dev') {
  416. $name = '花美灵';
  417. }
  418. $merchant = MerchantService::getByCondition(['name' => $name]);
  419. $list = wxUtil::getSubscribeUserList($merchant);
  420. dd($list);
  421. }
  422. //宝贝售出提醒 ssh 2020.1.30
  423. public function actionInform()
  424. {
  425. $merchant = MerchantService::getMerchantById(12362);
  426. $order = OrderService::getById(214810);
  427. InformAdminClass::sendComplete($order);
  428. }
  429. public function actionNotice()
  430. {
  431. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  432. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  433. echo '<pre>';
  434. print_r($data);
  435. $msg = serialize($data);
  436. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  437. }
  438. }