TestController.php 16 KB

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