TestController.php 14 KB

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