TestController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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', 'get'];
  20. public function actionGet()
  21. {
  22. ini_set('memory_limit', '2045M');
  23. set_time_limit(0);
  24. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  25. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  26. //还差 花悠星 花千朵 十年 杭州斗南 昱成 问境
  27. $arr = [
  28. //['name' => '国兰花尚', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  29. //['name' => '花掌柜', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
  30. //['name' => '纯彩花艺', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
  31. //['name' => '集美天天鲜花', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
  32. //['name' => '丰行花行', 'merchantNo' => '82260205992007P', 'wx' => [601053759, 601052157], 'zfb' => '2088820725885465'],
  33. ['name' => '独家花行', 'merchantNo' => '82239305992006Q', 'wx' => [601049483, 601048223], 'zfb' => '2088820725546555'],
  34. ['name' => '好多花海沧', 'merchantNo' => '82239305992006R', 'wx' => [601052177, 601053735], 'zfb' => '2088820725549695'],
  35. ['name' => '美天鲜花', 'merchantNo' => '82259505992003F', 'wx' => [601062064, 601138175], 'zfb' => '2088820729400990'],
  36. ['name' => '天天陈江店', 'merchantNo' => '82259505992003E', 'wx' => [601060616, 601059382], 'zfb' => '2088820725555368'],
  37. //['name' => '叶上花', 'merchantNo' => '82231805992002G', 'wx' => [601062892, 601062589], 'zfb' => '2088820728763546'],
  38. ['name' => '好又多(小明)', 'merchantNo' => '82239305992006S', 'wx' => [601135715, 601067347], 'zfb' => '2088820729698012'],
  39. ['name' => '我卖花', 'merchantNo' => '82227505992000R', 'wx' => [601177139, 601148755], 'zfb' => '2088820746424032'],
  40. ['name' => '七彩花都', 'merchantNo' => '8227310599200GF', 'wx' => [601176481, 601148503], 'zfb' => '2088820748594478'],
  41. //['name' => '都市花季', 'merchantNo' => '82239305992006U', 'wx' => [601174342, 601147649], 'zfb' => '2088820748507346'],
  42. //['name' => '花样年华', 'merchantNo' => '82260205992007Q', 'wx' => [601134352, 601091710], 'zfb' => '2088820735043444'],
  43. //['name' => '精茂城', 'merchantNo' => '8225840599200TF', 'wx' => [601173752, 601143352], 'zfb' => '2088820746800005'],
  44. ['name' => '莱漫', 'merchantNo' => '82239305992006T', 'wx' => [601134065, 601125595], 'zfb' => '2088820743859918'],
  45. //['name' => '福州我要花', 'merchantNo' => '82239105992007J', 'wx' => [601134030, 601128111], 'zfb' => '2088820745276973'],
  46. ['name' => '泉城', 'merchantNo' => '82239705992004E', 'wx' => [601133056, 601133821], 'zfb' => '2088820746111323'],
  47. ['name' => '美丽花行', 'merchantNo' => '82239305992006V', 'wx' => [601155249, 601149712], 'zfb' => '2088820747673312'],
  48. ['name' => '三叶', 'merchantNo' => '82236805992001Y', 'wx' => [601152233, 601151024], 'zfb' => '2088820747556725'],
  49. //['name' => '花大苪', 'merchantNo' => '8227310599200GG', 'wx' => [601174221, 601165136], 'zfb' => '2088820751181377'],
  50. ['name' => '十堰天天鲜花', 'merchantNo' => '82252305992001S', 'wx' => [601171131, 601170642], 'zfb' => '2088820750844626'],
  51. //['name' => '珑松花卉', 'merchantNo' => '82260205992007S', 'wx' => [601176093, 601174262], 'zfb' => '2088820754742492'],
  52. //['name' => '惠雅鲜花', 'merchantNo' => '82260205992007R', 'wx' => [601173390, 601174002], 'zfb' => '2088820753174540'],
  53. ['name' => '锦绣花卉', 'merchantNo' => '82252305992001T', 'wx' => [601176719, 601176660], 'zfb' => '2088820754751663'],
  54. ['name' => '祥瑞鲜花同安店', 'merchantNo' => '82239305992006W', 'wx' => [601178350, 601177795], 'zfb' => '2088820755715024'],
  55. ['name' => '祥瑞鲜花翔安店', 'merchantNo' => '82239305992006X', 'wx' => [601178260, 601178199], 'zfb' => '2088820754481553'],
  56. ['name' => '初见花季', 'merchantNo' => '82239305992006Y', 'wx' => [601178998, 601179605], 'zfb' => '2088820757223312'],
  57. ['name' => '荣发鲜花', 'merchantNo' => '82242705992000D', 'wx' => [601179681, 601179180], 'zfb' => '2088820756926593'],
  58. //['name' => '源花汇', 'merchantNo' => '82222105992004A', 'wx' => [601221944, 601214269], 'zfb' => '2088820770594246'],
  59. //['name' => '源花汇2(没用)', 'merchantNo' => '8227310599200GD', 'wx' => [601136305, 601067016], 'zfb' => '2088820729832744'],
  60. ];
  61. $new = [];
  62. foreach ($arr as $item) {
  63. $wx = $item['wx'];
  64. $zfb = $item['zfb'];
  65. $merchantNo = $item['merchantNo'];
  66. $name = $item['name'] . ' ' . $merchantNo;
  67. $group = [];
  68. foreach ($wx as $oneWx) {
  69. $params = [
  70. 'appid' => 'OP00002119',
  71. 'serial_no' => '018b08cfddbd',
  72. 'merchant_no' => $merchantNo,
  73. 'term_no' => 'C6337694',
  74. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  75. 'lklCertificatePath' => $lklCertificatePath,
  76. ];
  77. $data = [
  78. 'subMerchantId' => $oneWx,
  79. 'tradeMode' => 'WECHAT',
  80. ];
  81. $laResource = new Lakala($params);
  82. $response = $laResource->openStateQuery($data);
  83. $statusName = '出错了';
  84. if ($response['retCode'] == '000000') {
  85. $checkResult = $response['respData']['checkResult'] ?? '';
  86. $statusName = '未确认';
  87. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
  88. $statusName = '已确认';
  89. }
  90. }
  91. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  92. }
  93. $params = [
  94. 'appid' => 'OP00002119',
  95. 'serial_no' => '018b08cfddbd',
  96. 'merchant_no' => $merchantNo,
  97. 'term_no' => 'C6337694',
  98. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  99. 'lklCertificatePath' => $lklCertificatePath,
  100. ];
  101. $data = [
  102. 'subMerchantId' => $zfb,
  103. 'tradeMode' => 'ALIPAY',
  104. ];
  105. $laResource = new Lakala($params);
  106. $response = $laResource->openStateQuery($data);
  107. $statusName = '出错了';
  108. if ($response['retCode'] == '000000') {
  109. $checkResult = $response['respData']['checkResult'] ?? '';
  110. $statusName = '未确认';
  111. if ($checkResult == 'AUTHORIZED') {
  112. $statusName = '已确认';
  113. }
  114. }
  115. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  116. $new[] = ['name' => $name, 'status' => $group];
  117. }
  118. echo '<pre>';
  119. print_r($new);
  120. die;
  121. }
  122. public function actionAliRun2()
  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. $outTradeNo = orderSn::getPurchaseSn();
  135. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  136. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  137. $aliParams = [
  138. 'orderSn' => $outTradeNo,
  139. 'amount' => 0.16,
  140. 'capitalType' => $currentCapitalType,
  141. 'notifyUrl' => $notifyUrl,
  142. ];
  143. $laResource = new Lakala($params);
  144. $response = $laResource->driveAliPay($aliParams);
  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. public function actionAliRun3()
  156. {
  157. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  158. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  159. $params = [
  160. 'appid' => 'OP00002119',
  161. 'serial_no' => '018b08cfddbd',
  162. 'merchant_no' => '82240505992000N',
  163. 'term_no' => 'C6337694',
  164. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  165. 'lklCertificatePath' => $lklCertificatePath,
  166. ];
  167. $laResource = new Lakala($params);
  168. $outTradeNo = orderSn::getPurchaseSn();
  169. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  170. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  171. $wxParams = [
  172. 'orderSn' => $outTradeNo,
  173. 'amount' => 0.16,
  174. 'capitalType' => $currentCapitalType,
  175. 'notifyUrl' => $notifyUrl,
  176. ];
  177. $response = $laResource->driveWxPay($wxParams);
  178. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  179. echo '<pre>';
  180. echo "下单成功<br/>";
  181. print_r($response);
  182. } else {
  183. echo '<pre>';
  184. echo "下单失败<br/>";
  185. print_r($response);
  186. }
  187. }
  188. //dada 城市code
  189. public function actionDadaCityCode()
  190. {
  191. $res = dada::getCityCode(0);
  192. util::success($res);
  193. }
  194. //理由
  195. public function actionDadaReasons()
  196. {
  197. $res = dada::getCancelReason(0);
  198. util::success($res);
  199. }
  200. //达达 :下单
  201. public function actionDadaAddOrder()
  202. {
  203. $orderSn = 'XSD_CS26316851';
  204. $orderInfo = OrderClass::getByOrderSn($orderSn);
  205. $res = DadaExpressServices::addOrder($orderInfo);
  206. util::success($res);
  207. }
  208. //重发快递
  209. public function actionDadaReAdd()
  210. {
  211. $orderSn = 'XSD_CS26316851';
  212. $orderInfo = OrderClass::getByOrderSn($orderSn);
  213. $res = DadaExpressServices::reAddOrder($orderInfo);
  214. util::success($res);
  215. }
  216. //达达状态查询
  217. public function actionDadaOrderStatus()
  218. {
  219. $orderSn = 'XSD_CS26316851';
  220. $res = DadaExpressServices::statusOrder($orderSn);
  221. util::success($res);
  222. }
  223. //达达取消下单
  224. public function actionDadaCancelOrder()
  225. {
  226. $orderSn = 'XSD_CS26316851';
  227. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  228. util::success($res);
  229. }
  230. //获取已支持的配送公司列表接口
  231. public function actionGetAllDelivery()
  232. {
  233. $data = MiniExpressService::getAllImmeDelivery();
  234. util::success($data);
  235. }
  236. //即时配送
  237. /*
  238. * Array
  239. (
  240. [resultcode] => 0
  241. [resultmsg] => OK
  242. [shop_list] => Array
  243. (
  244. [0] => Array
  245. (
  246. [shopid] => 1588714266
  247. [delivery_id] => SFTC
  248. [audit_result] => 0
  249. [create_time] => 1612172838
  250. [remark] =>
  251. [delivery_name] => 顺丰同城急送
  252. )
  253. )
  254. )
  255. */
  256. public function actionGetBindAccount()
  257. {
  258. $merchant = WxOpenClass::getGhsWxInfo();
  259. $isOpen = 2;
  260. $r = miniUtil::getBindAccount($merchant, $isOpen);
  261. dd($r);
  262. }
  263. //下单 (沙箱)
  264. /**
  265. * Array
  266. * (
  267. * [resultcode] => 0
  268. * [resultmsg] => ok
  269. * [fee] => 10
  270. * [waybill_id] => test_shop_id1612365974_waybillid
  271. * [order_status] => 101
  272. * [dispatch_duration] => 300
  273. * )
  274. */
  275. public function actionCreateWaybill()
  276. {
  277. $merchant = WxOpenClass::getGhsWxInfo();
  278. $isOpen = 2;
  279. $shopId = 'test_shop_id';
  280. $shopOrderId = 'test_shop_id' . time();
  281. $appSecret = 'test_app_secrect';
  282. $data = [
  283. 'shopid' => $shopId,
  284. 'shop_order_id' => $shopOrderId,
  285. 'shop_no' => '1',
  286. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  287. 'delivery_id' => "TEST",
  288. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  289. 'sender' => [
  290. 'name' => 'test',
  291. 'city' => '厦门市',
  292. 'address' => '思明区',
  293. 'address_detail' => '软件园二期',
  294. 'phone' => '19959271111',
  295. 'lng' => 118.134343,
  296. 'lat' => 24.483566,
  297. 'coordinate_type' => 0,
  298. ],
  299. 'receiver' => [
  300. 'name' => 'test',
  301. 'city' => '厦门市',
  302. 'address' => '思明区',
  303. 'address_detail' => '软件园二期',
  304. 'phone' => '19959271111',
  305. 'lng' => 118.134343,
  306. 'lat' => 24.493566,
  307. 'coordinate_type' => 0,
  308. ],
  309. 'cargo' => [
  310. 'goods_value' => 1,
  311. 'goods_weight' => 0.1,
  312. 'cargo_first_class' => '鲜花',
  313. 'cargo_second_class' => '鲜花',
  314. ],
  315. 'order_info' => [
  316. 'order_type' => 0,
  317. ],
  318. 'shop' => [
  319. 'wxa_path' => '/shop',
  320. 'img_url' => 'http://www.baidu.com/test.png',
  321. 'goods_name' => 'test',
  322. 'goods_count' => 1,
  323. ],
  324. ];
  325. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  326. dd($r);
  327. }
  328. //获取运单数据
  329. /**
  330. * Array
  331. * (
  332. * [resultcode] => 0
  333. * [resultmsg] => ok
  334. * [order_status] => 101
  335. * [agent_info] => Array
  336. * (
  337. * )
  338. *
  339. * [waybill_id] => test_shop_id1612365974_waybillid
  340. * [rider_name] =>
  341. * [rider_phone] =>
  342. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  343. * )
  344. */
  345. public function actionGetOrder()
  346. {
  347. $shopId = 'test_shop_id';
  348. $shopOrderId = 'test_shop_id1612365974';
  349. $appSecret = 'test_app_secrect';
  350. $merchant = WxOpenClass::getGhsWxInfo();
  351. $isOpen = 2;
  352. $data = [
  353. 'shopid' => $shopId,
  354. 'shop_order_id' => $shopOrderId,
  355. 'shop_no' => '1',
  356. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  357. ];
  358. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  359. dd($r);
  360. }
  361. //沙盒 更新快递状态
  362. public function actionMockUpdateOrder()
  363. {
  364. $merchant = WxOpenClass::getGhsWxInfo();
  365. $isOpen = 2;
  366. /**
  367. * {
  368. * "shopid": "test_shop_id",
  369. * "shop_order_id": "xxxxxxxxxxx",
  370. * "waybill_id": "xxxxxxxxxxxxx",
  371. * "action_time": 12345678,
  372. * "order_status": 101,
  373. * "action_msg": "",
  374. * }
  375. */
  376. $shopId = 'test_shop_id';
  377. $shopOrderId = 'test_shop_id1612365974';
  378. $data = [
  379. 'shop_order_id' => $shopOrderId,
  380. "shopid" => $shopId,
  381. "action_time" => time(),
  382. "order_status" => 302,
  383. 'action_msg' => '状态变更',
  384. ];
  385. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  386. dd($r);
  387. }
  388. public function actionTest()
  389. {
  390. }
  391. //新增订单
  392. public function actionAddOrder()
  393. {
  394. $dada = Yii::getAlias("@vendor/dada/");
  395. require_once $dada . 'api/addOrderApi.php';
  396. require_once $dada . 'client/dadaRequestClient.php';
  397. require_once $dada . 'client/dadaResponse.php';
  398. require_once $dada . 'config/config.php';
  399. require_once $dada . 'model/orderModel.php';
  400. // isOnline 判断是否是测试环境,会有不同的域名等
  401. $isOnline = false;
  402. $sourceId = 1000000;
  403. // 初始化一个config
  404. $config = new \Config($sourceId, $isOnline);
  405. $orderModel = new \OrderModel();
  406. $orderModel->setShopNo('11047059');
  407. $orderModel->setOriginId('2018091100000002');
  408. $orderModel->setCityCode('021');
  409. $orderModel->setCargoPrice(10);
  410. $orderModel->setIsPrepay(0);
  411. $orderModel->setReceiverName('测试达达');
  412. $orderModel->setReceiverAddress('上海市崇明岛');
  413. $orderModel->setReceiverLat(31.63);
  414. $orderModel->setReceiverLng(121.41);
  415. $orderModel->setReceiverPhone('18588888888');
  416. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  417. // api主要有2个参数,一个是url, 一个是业务参数
  418. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  419. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  420. $resp = $dada_client->makeRequest();
  421. echo json_encode($resp);
  422. }
  423. //订单详情查询
  424. public function actionOrderQuery()
  425. {
  426. $dada = Yii::getAlias("@vendor/dada/");
  427. require_once $dada . 'api/OrderQueryApi.php';
  428. require_once $dada . 'client/dadaRequestClient.php';
  429. require_once $dada . 'client/dadaResponse.php';
  430. require_once $dada . 'config/config.php';
  431. require_once $dada . 'model/orderModel.php';
  432. // isOnline 判断是否是测试环境,会有不同的域名等
  433. $isOnline = false;
  434. $sourceId = 1000000;
  435. // 初始化一个config
  436. $config = new \Config($sourceId, $isOnline);
  437. $orderModel = new \OrderModel();
  438. $orderModel->setOrderId('2018091100000002');
  439. // api主要有2个参数,一个是url, 一个是业务参数
  440. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  441. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  442. $resp = $dada_client->makeRequest();
  443. echo json_encode($resp);
  444. }
  445. public function actionFocus()
  446. {
  447. $name = '花卉宝';
  448. if (getenv('YII_ENV') == 'dev') {
  449. $name = '花美灵';
  450. }
  451. $merchant = MerchantService::getByCondition(['name' => $name]);
  452. $list = wxUtil::getSubscribeUserList($merchant);
  453. dd($list);
  454. }
  455. //宝贝售出提醒 ssh 2020.1.30
  456. public function actionInform()
  457. {
  458. $merchant = MerchantService::getMerchantById(12362);
  459. $order = OrderService::getById(214810);
  460. InformAdminClass::sendComplete($order);
  461. }
  462. public function actionNotice()
  463. {
  464. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  465. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  466. echo '<pre>';
  467. print_r($data);
  468. $msg = serialize($data);
  469. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  470. }
  471. }