TestController.php 8.1 KB

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