TestController.php 12 KB

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