TestController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantService;
  4. use bizHd\message\classes\InformAdminClass;
  5. use bizHd\message\services\InformAdminService;
  6. use bizHd\order\services\OrderService;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use bizGhs\express\services\MiniExpressService;
  9. use bizGhs\product\classes\ProductClass;
  10. use common\components\dada\dada;
  11. use common\components\miniUtil;
  12. use common\components\wxUtil;
  13. use Yii;
  14. use common\components\util;
  15. class TestController extends BaseController
  16. {
  17. public $guestAccessAction = ['inform', 'notice','order-query','add-order'];
  18. //dada 城市code
  19. public function actionDadaCityCode()
  20. {
  21. $res = dada::getCityCode(0);
  22. util::success($res);
  23. }
  24. //获取已支持的配送公司列表接口
  25. public function actionGetAllDelivery()
  26. {
  27. $data = MiniExpressService::getAllImmeDelivery();
  28. util::success($data);
  29. }
  30. //即时配送
  31. /*
  32. * Array
  33. (
  34. [resultcode] => 0
  35. [resultmsg] => OK
  36. [shop_list] => Array
  37. (
  38. [0] => Array
  39. (
  40. [shopid] => 1588714266
  41. [delivery_id] => SFTC
  42. [audit_result] => 0
  43. [create_time] => 1612172838
  44. [remark] =>
  45. [delivery_name] => 顺丰同城急送
  46. )
  47. )
  48. )
  49. */
  50. public function actionGetBindAccount()
  51. {
  52. $merchant = WxOpenClass::getGhsWxInfo();
  53. $isOpen = 2;
  54. $r = miniUtil::getBindAccount($merchant, $isOpen);
  55. dd($r);
  56. }
  57. //下单 (沙箱)
  58. /**
  59. * Array
  60. (
  61. [resultcode] => 0
  62. [resultmsg] => ok
  63. [fee] => 10
  64. [waybill_id] => test_shop_id1612365974_waybillid
  65. [order_status] => 101
  66. [dispatch_duration] => 300
  67. )
  68. */
  69. public function actionCreateWaybill()
  70. {
  71. $merchant = WxOpenClass::getGhsWxInfo();
  72. $isOpen = 2;
  73. $shopId = 'test_shop_id';
  74. $shopOrderId = 'test_shop_id'.time();
  75. $appSecret = 'test_app_secrect';
  76. $data = [
  77. 'shopid'=>$shopId,
  78. 'shop_order_id'=>$shopOrderId,
  79. 'shop_no'=>'1',
  80. 'delivery_sign'=>miniUtil::getDeliverySign($shopId,$shopOrderId,$appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  81. 'delivery_id'=>"TEST",
  82. 'openid'=>'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  83. 'sender'=>[
  84. 'name'=>'test',
  85. 'city'=>'厦门市',
  86. 'address'=>'思明区',
  87. 'address_detail'=>'软件园二期',
  88. 'phone'=>'19959271111',
  89. 'lng'=>118.134343,
  90. 'lat'=>24.483566,
  91. 'coordinate_type'=>0,
  92. ],
  93. 'receiver'=>[
  94. 'name'=>'test',
  95. 'city'=>'厦门市',
  96. 'address'=>'思明区',
  97. 'address_detail'=>'软件园二期',
  98. 'phone'=>'19959271111',
  99. 'lng'=>118.134343,
  100. 'lat'=>24.493566,
  101. 'coordinate_type'=>0,
  102. ],
  103. 'cargo'=>[
  104. 'goods_value'=>1,
  105. 'goods_weight'=>0.1,
  106. 'cargo_first_class'=>'鲜花',
  107. 'cargo_second_class'=>'鲜花',
  108. ],
  109. 'order_info'=>[
  110. 'order_type'=>0,
  111. ],
  112. 'shop'=>[
  113. 'wxa_path'=>'/shop',
  114. 'img_url'=>'http://www.baidu.com/test.png',
  115. 'goods_name'=>'test',
  116. 'goods_count'=>1,
  117. ],
  118. ];
  119. $r = miniUtil::addOrder($data,$merchant, $isOpen);
  120. dd($r);
  121. }
  122. //获取运单数据
  123. /**
  124. * Array
  125. (
  126. [resultcode] => 0
  127. [resultmsg] => ok
  128. [order_status] => 101
  129. [agent_info] => Array
  130. (
  131. )
  132. [waybill_id] => test_shop_id1612365974_waybillid
  133. [rider_name] =>
  134. [rider_phone] =>
  135. [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  136. )
  137. */
  138. public function actionGetOrder()
  139. {
  140. $shopId = 'test_shop_id';
  141. $shopOrderId ='test_shop_id1612365974';
  142. $appSecret = 'test_app_secrect';
  143. $merchant = WxOpenClass::getGhsWxInfo();
  144. $isOpen = 2;
  145. $data = [
  146. 'shopid'=>$shopId,
  147. 'shop_order_id'=>$shopOrderId,
  148. 'shop_no'=>'1',
  149. 'delivery_sign'=>MiniExpressService::getDeliverySign($shopId,$shopOrderId,$appSecret),
  150. ];
  151. $r = miniUtil::getOrder($data,$merchant, $isOpen);
  152. dd($r);
  153. }
  154. //沙盒 更新快递状态
  155. public function actionMockUpdateOrder()
  156. {
  157. $merchant = WxOpenClass::getGhsWxInfo();
  158. $isOpen = 2;
  159. /**
  160. * {
  161. "shopid": "test_shop_id",
  162. "shop_order_id": "xxxxxxxxxxx",
  163. "waybill_id": "xxxxxxxxxxxxx",
  164. "action_time": 12345678,
  165. "order_status": 101,
  166. "action_msg": "",
  167. }
  168. */
  169. $shopId = 'test_shop_id';
  170. $shopOrderId ='test_shop_id1612365974';
  171. $data = [
  172. 'shop_order_id'=>$shopOrderId,
  173. "shopid"=>$shopId,
  174. "action_time"=>time(),
  175. "order_status"=>302,
  176. 'action_msg'=>'状态变更',
  177. ];
  178. $r = miniUtil::mockUpdateOrder($data,$merchant, $isOpen);
  179. dd($r);
  180. }
  181. public function actionTest()
  182. {
  183. }
  184. //新增订单
  185. public function actionAddOrder()
  186. {
  187. $dada = Yii::getAlias("@vendor/dada/");
  188. require_once $dada . 'api/addOrderApi.php';
  189. require_once $dada . 'client/dadaRequestClient.php';
  190. require_once $dada . 'client/dadaResponse.php';
  191. require_once $dada . 'config/config.php';
  192. require_once $dada . 'model/orderModel.php';
  193. // isOnline 判断是否是测试环境,会有不同的域名等
  194. $isOnline = false;
  195. $sourceId = 1000000;
  196. // 初始化一个config
  197. $config = new \Config($sourceId, $isOnline);
  198. $orderModel = new \OrderModel();
  199. $orderModel->setShopNo('11047059');
  200. $orderModel->setOriginId('2018091100000002');
  201. $orderModel->setCityCode('021');
  202. $orderModel->setCargoPrice(10);
  203. $orderModel->setIsPrepay(0);
  204. $orderModel->setReceiverName('测试达达');
  205. $orderModel->setReceiverAddress('上海市崇明岛');
  206. $orderModel->setReceiverLat(31.63);
  207. $orderModel->setReceiverLng(121.41);
  208. $orderModel->setReceiverPhone('18588888888');
  209. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  210. // api主要有2个参数,一个是url, 一个是业务参数
  211. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  212. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  213. $resp = $dada_client->makeRequest();
  214. echo json_encode($resp);
  215. }
  216. //订单详情查询
  217. public function actionOrderQuery()
  218. {
  219. $dada = Yii::getAlias("@vendor/dada/");
  220. require_once $dada . 'api/OrderQueryApi.php';
  221. require_once $dada . 'client/dadaRequestClient.php';
  222. require_once $dada . 'client/dadaResponse.php';
  223. require_once $dada . 'config/config.php';
  224. require_once $dada . 'model/orderModel.php';
  225. // isOnline 判断是否是测试环境,会有不同的域名等
  226. $isOnline = false;
  227. $sourceId = 1000000;
  228. // 初始化一个config
  229. $config = new \Config($sourceId, $isOnline);
  230. $orderModel = new \OrderModel();
  231. $orderModel->setOrderId('2018091100000002');
  232. // api主要有2个参数,一个是url, 一个是业务参数
  233. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  234. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  235. $resp = $dada_client->makeRequest();
  236. echo json_encode($resp);
  237. }
  238. public function actionFocus()
  239. {
  240. $name = '花卉宝';
  241. if (getenv('YII_ENV') == 'dev') {
  242. $name = '花美灵';
  243. }
  244. $merchant = MerchantService::getByCondition(['merchantName' => $name]);
  245. $list = wxUtil::getSubscribeUserList($merchant);
  246. dd($list);
  247. }
  248. //宝贝售出提醒 shish 2020.1.30
  249. public function actionInform()
  250. {
  251. $merchant = MerchantService::getMerchantById(12362);
  252. $order = OrderService::getById(214810);
  253. InformAdminClass::sendComplete($order);
  254. }
  255. public function actionNotice()
  256. {
  257. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  258. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  259. echo '<pre>';
  260. print_r($data);
  261. $msg = serialize($data);
  262. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  263. }
  264. }