TestController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\services\MerchantService;
  5. use biz\wx\classes\WxMessageClass;
  6. use bizGhs\express\services\DadaExpressServices;
  7. use bizGhs\order\classes\OrderClass;
  8. use bizHd\message\classes\InformAdminClass;
  9. use bizHd\order\services\OrderService;
  10. use bizHd\purchase\classes\PurchaseClass;
  11. use bizHd\wx\classes\WxOpenClass;
  12. use bizGhs\express\services\MiniExpressService;
  13. use common\components\dict;
  14. use common\components\lakala\Lakala;
  15. use common\components\miniUtil;
  16. use common\components\noticeUtil;
  17. use common\components\orderSn;
  18. use common\components\wxUtil;
  19. use common\components\payUtil;
  20. use Yii;
  21. use common\components\util;
  22. class TestController extends BaseController
  23. {
  24. public $guestAccess = ['apply', 'ls-trade-query', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund'];
  25. //退款操作 ssh 20231029
  26. public function actionRefund()
  27. {
  28. $shopId = 36524;
  29. $shop = ShopClass::getById($shopId, true);
  30. if (empty($shop)) {
  31. util::fail('没有找到门店');
  32. }
  33. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  34. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  35. $params = [
  36. 'appid' => 'OP00002119',
  37. 'serial_no' => '018b08cfddbd',
  38. 'merchant_no' => $shop->lklSjNo,
  39. 'term_no' => $shop->lklB2BTermNo,
  40. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  41. 'lklCertificatePath' => $lklCertificatePath,
  42. ];
  43. $laResource = new Lakala($params);
  44. $refundReason = '暂无';
  45. $refundOrderSn = orderSn::getCgRefundSn();
  46. $refundPrice = 0.01;
  47. $refundFee = bcmul($refundPrice, 100);
  48. $orderSn = 'KD_CS61235203';
  49. $originTradeNo = '20231030110113230266215266468756';
  50. //$originLogNo = '66215266025626';
  51. $aliParams = [
  52. 'refundSn' => $refundOrderSn,
  53. 'orderSn' => $orderSn,
  54. 'refundAmount' => $refundFee,
  55. 'refundReason' => $refundReason,
  56. 'originTradeNo' => $originTradeNo,
  57. //'originLogNo' => $originLogNo,
  58. ];
  59. $response = $laResource->refund($aliParams);
  60. echo '<pre>';
  61. print_r($response);
  62. }
  63. public function actionApply()
  64. {
  65. $id = 2888;
  66. $shopId = 36524;
  67. $cg = PurchaseClass::getById($id, true);
  68. $shop = ShopClass::getById($shopId, true);
  69. WxMessageClass::hdNewCgOrderInform($shop, $cg);
  70. }
  71. public function actionGet()
  72. {
  73. ini_set('memory_limit', '2045M');
  74. set_time_limit(0);
  75. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  76. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  77. $arr = [
  78. //['name' => '国兰花尚OK', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  79. //['name' => '花掌柜OK', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
  80. //['name' => '纯彩花艺OK', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
  81. //['name' => '集美天天鲜花OK', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
  82. //['name' => '丰行花行OK', 'merchantNo' => '82260205992007P', 'wx' => [601053759, 601052157], 'zfb' => '2088820725885465'],
  83. //['name' => '独家花行OK', 'merchantNo' => '82239305992006Q', 'wx' => [601049483, 601048223], 'zfb' => '2088820725546555'],
  84. //['name' => '好多花海沧OK', 'merchantNo' => '82239305992006R', 'wx' => [601052177, 601053735], 'zfb' => '2088820725549695'],
  85. //['name' => '美天鲜花OK', 'merchantNo' => '82259505992003F', 'wx' => [601062064, 601138175], 'zfb' => '2088820729400990'],
  86. //['name' => '天天陈江店OK', 'merchantNo' => '82259505992003E', 'wx' => [601060616, 601059382], 'zfb' => '2088820725555368'],
  87. //['name' => '叶上花OK', 'merchantNo' => '82231805992002G', 'wx' => [601062892, 601062589], 'zfb' => '2088820728763546'],
  88. //['name' => '好又多(小明)OK', 'merchantNo' => '82239305992006S', 'wx' => [601135715, 601067347], 'zfb' => '2088820729698012'],
  89. //['name' => '我卖花OK', 'merchantNo' => '82227505992000R', 'wx' => [601177139, 601148755], 'zfb' => '2088820746424032'],
  90. //['name' => '问境OK', 'merchantNo' => '8226900599200KX', 'wx' => [601299388, 601299453], 'zfb' => '2088820787661843'],
  91. //['name' => '昱成OK', 'merchantNo' => '8226900599200KY', 'wx' => [601312993, 601325844], 'zfb' => '2088820788900240'],
  92. //['name' => '杭州斗南', 'merchantNo' => '杭州斗南', 'wx' => [601405963, 601405929], 'zfb' => '2088820793601705'],
  93. //['name' => '杭州斗南(没用)', 'merchantNo' => '8223310599200AD', 'wx' => [601254682, 601250805], 'zfb' => '2088820782666872'],
  94. //['name' => '珑松花卉长安店', 'merchantNo' => '82260205992007U', 'wx' => [602499045, 602497558], 'zfb' => '2088820959620797'],
  95. //['name' => '福州花福(个人)', 'merchantNo' => '82239105992007P', 'wx' => [603301197, 603302321], 'zfb' => '2088920058098261'],
  96. //['name' => '福州花福', 'merchantNo' => '82239105992007N', 'wx' => [602796807, 602774796], 'zfb' => '2088820996010582'],
  97. //['name' => '昆明新宏源', 'merchantNo' => '82239305992007H', 'wx' => [606098318, 606100317], 'zfb' => '2088920878302843'],
  98. //['name' => '昆明纯彩', 'merchantNo' => '82239905992003L', 'wx' => [604923629, 604922175], 'zfb' => '2088920533160795'],
  99. //['name' => '花优田(军兴旺)', 'merchantNo' => '8227310599200GX', 'wx' => [605191281, 605190492], 'zfb' => '2088920588715249'],
  100. ['name' => '广州国恋', 'merchantNo' => '8225810599200Q7', 'wx' => [612321716, 612320978], 'zfb' => '2088330479975012'],
  101. //['name' => '欣研鲜花', 'merchantNo' => '82260305992001Y', 'wx' => [612181234, 612181615], 'zfb' => '2088330365608286'],
  102. //['name' => '村长冷链', 'merchantNo' => '82260205992008G', 'wx' => [612168406, 612168000], 'zfb' => '2088330360870932'],
  103. //['name' => '惠州惠雅鲜花批发', 'merchantNo' => '82259505992003S', 'wx' => [611676975, 611677314], 'zfb' => '2088330136601427'],
  104. //['name' => '杭州斗南鲜花', 'merchantNo' => '8223310599200AR', 'wx' => [608955814, 608955082], 'zfb' => '2088130449323603'],
  105. //['name' => '营口简约花卉', 'merchantNo' => '8227310599200HJ', 'wx' => [608439898, 608440994], 'zfb' => '2088130112725929'],
  106. //['name' => '惠雅鲜花惠州店', 'merchantNo' => '82260205992007Z', 'wx' => [608406948, 608403207], 'zfb' => '2088130098167302'],
  107. //['name' => '云南珑松花卉珠海店', 'merchantNo' => '82258505992002U', 'wx' => [608062727, 608056474], 'zfb' => '2088030873238576'],
  108. //['name' => '买手很忙', 'merchantNo' => '8227310599200GJ', 'wx' => [601597167, 601595526], 'zfb' => '2088820818930267'],
  109. //['name' => '七彩花都', 'merchantNo' => '8227310599200GF', 'wx' => [601176481, 601148503], 'zfb' => '2088820748594478'],
  110. //['name' => '十年', 'merchantNo' => '82252305992001U', 'wx' => [601285154, 601261795], 'zfb' => '2088820782171763'],
  111. //['name' => '都市花季OK', 'merchantNo' => '82239305992006U', 'wx' => [601174342, 601147649], 'zfb' => '2088820748507346'],
  112. //['name' => '花样年华OK', 'merchantNo' => '82260205992007Q', 'wx' => [601134352, 601091710], 'zfb' => '2088820735043444'],
  113. //['name' => '精茂城OK', 'merchantNo' => '8225840599200TF', 'wx' => [601173752, 601143352], 'zfb' => '2088820746800005'],
  114. //['name' => '莱漫OK', 'merchantNo' => '82239305992007A', 'wx' => [601288494, 601288166], 'zfb' => '2088820783686611'],
  115. //['name' => '莱漫(没用)', 'merchantNo' => '82239305992006T', 'wx' => [601134065, 601125595], 'zfb' => '2088820743859918'],
  116. //['name' => '福州我要花OK', 'merchantNo' => '82239105992007J', 'wx' => [601134030, 601128111], 'zfb' => '2088820745276973'],
  117. //['name' => '泉城OK', 'merchantNo' => '82239705992004F', 'wx' => [601273270, 601272854], 'zfb' => '2088820784658561'],
  118. //['name' => '泉城(没用)', 'merchantNo' => '82239705992004E', 'wx' => [601133056, 601133821], 'zfb' => '2088820746111323'],
  119. //['name' => '美丽花行OK', 'merchantNo' => '82239305992006V', 'wx' => [601155249, 601149712], 'zfb' => '2088820747673312'],
  120. //['name' => '三叶OK', 'merchantNo' => '82236805992001Y', 'wx' => [601152233, 601151024], 'zfb' => '2088820747556725'],
  121. //['name' => '花大苪OK', 'merchantNo' => '8227310599200GG', 'wx' => [601174221, 601165136], 'zfb' => '2088820751181377'],
  122. //['name' => '十堰天天鲜花OK', 'merchantNo' => '82252305992001S', 'wx' => [601171131, 601170642], 'zfb' => '2088820750844626'],
  123. //['name' => '珑松花卉OK', 'merchantNo' => '82260205992007S', 'wx' => [601176093, 601174262], 'zfb' => '2088820754742492'],
  124. //['name' => '惠雅鲜花OK', 'merchantNo' => '82260205992007R', 'wx' => [601173390, 601174002], 'zfb' => '2088820753174540'],
  125. //['name' => '锦绣花卉OK', 'merchantNo' => '82252305992001T', 'wx' => [601176719, 601176660], 'zfb' => '2088820754751663'],
  126. //['name' => '祥瑞鲜花同安店OK', 'merchantNo' => '82239305992006W', 'wx' => [601178350, 601177795], 'zfb' => '2088820755715024'],
  127. //['name' => '祥瑞鲜花翔安店OK', 'merchantNo' => '82239305992006X', 'wx' => [601178260, 601178199], 'zfb' => '2088820754481553'],
  128. //['name' => '初见花季OK', 'merchantNo' => '82239305992006Y', 'wx' => [601178998, 601179605], 'zfb' => '2088820757223312'],
  129. //['name' => '荣发鲜花OK', 'merchantNo' => '82242705992000D', 'wx' => [601179681, 601179180], 'zfb' => '2088820756926593'],
  130. //['name' => '花千朵(多多)OK', 'merchantNo' => '82239305992006Z', 'wx' => [601223474, 601208096], 'zfb' => '2088820766783276'],
  131. //['name' => '花悠星OK', 'merchantNo' => '8225810599200NH', 'wx' => [601228194, 601227691], 'zfb' => '2088820774587446'],
  132. //['name' => '花悠星(没用)', 'merchantNo' => '8225810599200NG', 'wx' => [601223630, 601210952], 'zfb' => '2088820767072874'],
  133. //['name' => '源花汇OK', 'merchantNo' => '82222105992004A', 'wx' => [601221944, 601214269], 'zfb' => '2088820770594246'],
  134. //['name' => '源花汇2(没用)', 'merchantNo' => '8227310599200GD', 'wx' => [601136305, 601067016], 'zfb' => '2088820729832744'],
  135. ];
  136. $new = [];
  137. foreach ($arr as $item) {
  138. $wx = $item['wx'];
  139. $zfb = $item['zfb'];
  140. $merchantNo = $item['merchantNo'];
  141. $name = $item['name'] . ' ' . $merchantNo;
  142. $group = [];
  143. foreach ($wx as $oneWx) {
  144. $params = [
  145. 'appid' => 'OP00002119',
  146. 'serial_no' => '018b08cfddbd',
  147. 'merchant_no' => $merchantNo,
  148. 'term_no' => 'C6337694',
  149. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  150. 'lklCertificatePath' => $lklCertificatePath,
  151. ];
  152. $data = [
  153. 'subMerchantId' => $oneWx,
  154. 'tradeMode' => 'WECHAT',
  155. ];
  156. $laResource = new Lakala($params);
  157. $response = $laResource->openStateQuery($data);
  158. $statusName = '出错了';
  159. if ($response['retCode'] == '000000') {
  160. $checkResult = $response['respData']['checkResult'] ?? '';
  161. $statusName = '未认证';
  162. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
  163. $statusName = '已认证';
  164. }
  165. }
  166. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  167. }
  168. $params = [
  169. 'appid' => 'OP00002119',
  170. 'serial_no' => '018b08cfddbd',
  171. 'merchant_no' => $merchantNo,
  172. 'term_no' => 'C6337694',
  173. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  174. 'lklCertificatePath' => $lklCertificatePath,
  175. ];
  176. $data = [
  177. 'subMerchantId' => $zfb,
  178. 'tradeMode' => 'ALIPAY',
  179. ];
  180. $laResource = new Lakala($params);
  181. $response = $laResource->openStateQuery($data);
  182. $statusName = '出错了';
  183. if ($response['retCode'] == '000000') {
  184. $checkResult = $response['respData']['checkResult'] ?? '';
  185. $statusName = '未认证';
  186. if ($checkResult == 'AUTHORIZED') {
  187. $statusName = '已认证';
  188. }
  189. }
  190. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  191. $new[] = ['name' => $name, 'status' => $group];
  192. }
  193. echo '<pre>';
  194. print_r($new);
  195. die;
  196. }
  197. public function actionRefundQuery()
  198. {
  199. $shopId = 520;
  200. $shop = ShopClass::getById($shopId, true);
  201. if (empty($shop)) {
  202. util::stop('没有找到门店');
  203. }
  204. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  205. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  206. $params = [
  207. 'appid' => 'OP00002119',
  208. 'serial_no' => '018b08cfddbd',
  209. 'merchant_no' => $shop->lklSjNo,
  210. 'term_no' => $shop->lklScanTermNo,
  211. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  212. 'lklCertificatePath' => $lklCertificatePath,
  213. ];
  214. $laResource = new Lakala($params);
  215. $orderSn = '20231201110113131266165492618754';
  216. $data = [
  217. 'orderSn' => $orderSn,
  218. ];
  219. $response = $laResource->refundQuery($data);
  220. echo "<pre>";
  221. print_r($response);
  222. }
  223. public function actionBalanceQuery()
  224. {
  225. $shopId = 1212;
  226. $shop = ShopClass::getById($shopId, true);
  227. if (empty($shop)) {
  228. util::stop('没有找到门店');
  229. }
  230. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  231. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  232. $params = [
  233. 'appid' => 'OP00002119',
  234. 'serial_no' => '018b08cfddbd',
  235. 'merchant_no' => $shop->lklSjNo,
  236. 'term_no' => $shop->lklScanTermNo,
  237. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  238. 'lklCertificatePath' => $lklCertificatePath,
  239. ];
  240. $laResource = new Lakala($params);
  241. $response = $laResource->accountBalanceQuery();
  242. echo "<pre>";
  243. print_r($response);
  244. }
  245. //测试环境查线上数据 ssh 20231230
  246. public function actionCsQuery()
  247. {
  248. // $shopId = 1527;
  249. // $shop = ShopClass::getById($shopId, true);
  250. // if (empty($shop)) {
  251. // util::stop('没有找到门店');
  252. // }
  253. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  254. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  255. $params = [
  256. 'appid' => 'OP00002119',
  257. 'serial_no' => '018b08cfddbd',
  258. //'merchant_no' => $shop->lklSjNo,
  259. 'merchant_no' => '82222105992004A',
  260. //'term_no' => $shop->lklScanTermNo,
  261. 'term_no' => 'H3656802',
  262. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  263. 'lklCertificatePath' => $lklCertificatePath,
  264. ];
  265. $laResource = new Lakala($params);
  266. $queryParams = [
  267. //'orderSn' => 'KD26452235',
  268. 'tradeNo' => '20231230110113130266215700775011',
  269. ];
  270. $response = $laResource->query($queryParams, 1);
  271. echo "<pre>";
  272. print_r($response);
  273. }
  274. public function actionQuery()
  275. {
  276. // $shopId = 1527;
  277. // $shop = ShopClass::getById($shopId, true);
  278. // if (empty($shop)) {
  279. // util::stop('没有找到门店');
  280. // }
  281. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  282. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  283. $params = [
  284. 'appid' => 'OP00002119',
  285. 'serial_no' => '018b08cfddbd',
  286. //'merchant_no' => $shop->lklSjNo,
  287. 'merchant_no' => '82222105992004A',
  288. //'term_no' => $shop->lklScanTermNo,
  289. 'term_no' => 'H3656802',
  290. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  291. 'lklCertificatePath' => $lklCertificatePath,
  292. ];
  293. $laResource = new Lakala($params);
  294. $queryParams = [
  295. //'orderSn' => 'KD26452235',
  296. 'tradeNo' => '20231230110113130266215700775011',
  297. ];
  298. $response = $laResource->query($queryParams, 1);
  299. echo "<pre>";
  300. print_r($response);
  301. }
  302. //零售订单查询 ssh 20231031
  303. public function actionLsTradeQuery()
  304. {
  305. $shopId = 1422;
  306. $shop = ShopClass::getById($shopId, true);
  307. if (empty($shop)) {
  308. util::stop('没有找到门店');
  309. }
  310. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  311. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  312. $params = [
  313. 'appid' => 'OP00002119',
  314. 'serial_no' => '018b08cfddbd',
  315. 'merchant_no' => $shop->lklSjNo,
  316. 'term_no' => $shop->lklScanTermNo,
  317. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  318. 'lklCertificatePath' => $lklCertificatePath,
  319. ];
  320. $laResource = new Lakala($params);
  321. $queryParams = [
  322. 'orderSn' => 'KD26461864',
  323. //'tradeNo' => '20231029110113130266215259252887',
  324. ];
  325. $response = $laResource->query($queryParams, 0);
  326. print_r($response);
  327. util::stop();
  328. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  329. $connection = Yii::$app->db;
  330. $transaction = $connection->beginTransaction();
  331. try {
  332. $postData = $response['resp_data'] ?? [];
  333. $orderSn = $postData['out_trade_no'] ?? '';
  334. $total_amount = $postData['total_amount'] ?? 0;
  335. $account_type = $postData['account_type'] ?? '';
  336. if (empty($account_type)) {
  337. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  338. util::end();
  339. }
  340. $totalFee = $total_amount / 100;
  341. $transactionId = $postData['trade_no'] ?? 0;
  342. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  343. $currentPayWay = null;
  344. if ($account_type == 'WECHAT') {
  345. $currentPayWay = dict::getDict('payWay', 'wxPay');
  346. } elseif ($account_type == 'ALIPAY') {
  347. $currentPayWay = dict::getDict('payWay', 'alipay');
  348. } else {
  349. noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
  350. util::end();
  351. }
  352. $attach = '';
  353. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  354. $transaction->commit();
  355. echo 'OK';
  356. } catch (\Exception $e) {
  357. $transaction->rollBack();
  358. Yii::error("失败原因:" . $e->getMessage());
  359. }
  360. }
  361. }
  362. //交易查询 ssh 20231021
  363. public function actionTradeQuery()
  364. {
  365. $shopId = 520;
  366. $shop = ShopClass::getById($shopId, true);
  367. if (empty($shop)) {
  368. util::stop('没有找到门店');
  369. }
  370. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  371. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  372. $params = [
  373. 'appid' => 'OP00002119',
  374. 'serial_no' => '018b08cfddbd',
  375. 'merchant_no' => $shop->lklSjNo,
  376. 'term_no' => $shop->lklScanTermNo,
  377. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  378. 'lklCertificatePath' => $lklCertificatePath,
  379. ];
  380. $laResource = new Lakala($params);
  381. $queryParams = [
  382. 'orderSn' => 'CG26741062',
  383. //'tradeNo' => '20231029110113130266215259252887',
  384. ];
  385. $response = $laResource->query($queryParams, 0);
  386. print_r($response);
  387. util::stop();
  388. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  389. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  390. $connection = Yii::$app->db;
  391. $transaction = $connection->beginTransaction();
  392. try {
  393. $account_type = $response['resp_data']['account_type'] ?? 0;
  394. if (empty($account_type)) {
  395. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意', '15280215347');
  396. util::end();
  397. }
  398. $currentPayWay = null;
  399. if ($account_type == 'WECHAT') {
  400. $currentPayWay = dict::getDict('payWay', 'wxPay');
  401. } elseif ($account_type == 'ALIPAY') {
  402. $currentPayWay = dict::getDict('payWay', 'alipay');
  403. } else {
  404. noticeUtil::push('支付回调失败了,没有找到支付类型', '15280215347');
  405. util::end();
  406. }
  407. $attach = '';
  408. $total_amount = $response['resp_data']['total_amount'] ?? 0;
  409. $orderSn = $response['resp_data']['out_trade_no'] ?? 0;
  410. $totalFee = $total_amount / 100;
  411. $transactionId = $response['resp_data']['trade_no'] ?? 0;
  412. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  413. $transaction->commit();
  414. echo 'OK';
  415. } catch (\Exception $e) {
  416. $transaction->rollBack();
  417. Yii::error("失败原因:" . $e->getMessage());
  418. }
  419. }
  420. }
  421. public function actionAliRun2()
  422. {
  423. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  424. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  425. $params = [
  426. 'appid' => 'OP00002119',
  427. 'serial_no' => '018b08cfddbd',
  428. 'merchant_no' => '82240505992000N',
  429. 'term_no' => 'C6337694',
  430. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  431. 'lklCertificatePath' => $lklCertificatePath,
  432. ];
  433. $outTradeNo = orderSn::getPurchaseSn();
  434. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  435. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  436. $aliParams = [
  437. 'orderSn' => $outTradeNo,
  438. 'amount' => 0.16,
  439. 'capitalType' => $currentCapitalType,
  440. 'notifyUrl' => $notifyUrl,
  441. ];
  442. $laResource = new Lakala($params);
  443. $response = $laResource->driveAliPay($aliParams);
  444. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  445. echo '<pre>';
  446. echo "下单成功<br/>";
  447. print_r($response);
  448. } else {
  449. echo '<pre>';
  450. echo "下单失败<br/>";
  451. print_r($response);
  452. }
  453. }
  454. public function actionAliRun3()
  455. {
  456. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  457. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  458. $params = [
  459. 'appid' => 'OP00002119',
  460. 'serial_no' => '018b08cfddbd',
  461. 'merchant_no' => '82240505992000N',
  462. 'term_no' => 'C6337694',
  463. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  464. 'lklCertificatePath' => $lklCertificatePath,
  465. ];
  466. $laResource = new Lakala($params);
  467. $outTradeNo = orderSn::getPurchaseSn();
  468. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  469. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  470. $wxParams = [
  471. 'orderSn' => $outTradeNo,
  472. 'amount' => 0.16,
  473. 'capitalType' => $currentCapitalType,
  474. 'notifyUrl' => $notifyUrl,
  475. ];
  476. $response = $laResource->driveWxPay($wxParams);
  477. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  478. echo '<pre>';
  479. echo "下单成功<br/>";
  480. print_r($response);
  481. } else {
  482. echo '<pre>';
  483. echo "下单失败<br/>";
  484. print_r($response);
  485. }
  486. }
  487. //dada 城市code
  488. public function actionDadaCityCode()
  489. {
  490. $res = dada::getCityCode(0);
  491. util::success($res);
  492. }
  493. //理由
  494. public function actionDadaReasons()
  495. {
  496. $res = dada::getCancelReason(0);
  497. util::success($res);
  498. }
  499. //达达 :下单
  500. public function actionDadaAddOrder()
  501. {
  502. $orderSn = 'XSD_CS26316851';
  503. $orderInfo = OrderClass::getByOrderSn($orderSn);
  504. $res = DadaExpressServices::addOrder($orderInfo);
  505. util::success($res);
  506. }
  507. //重发快递
  508. public function actionDadaReAdd()
  509. {
  510. $orderSn = 'XSD_CS26316851';
  511. $orderInfo = OrderClass::getByOrderSn($orderSn);
  512. $res = DadaExpressServices::reAddOrder($orderInfo);
  513. util::success($res);
  514. }
  515. //达达状态查询
  516. public function actionDadaOrderStatus()
  517. {
  518. $orderSn = 'XSD_CS26316851';
  519. $res = DadaExpressServices::statusOrder($orderSn);
  520. util::success($res);
  521. }
  522. //达达取消下单
  523. public function actionDadaCancelOrder()
  524. {
  525. $orderSn = 'XSD_CS26316851';
  526. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  527. util::success($res);
  528. }
  529. //获取已支持的配送公司列表接口
  530. public function actionGetAllDelivery()
  531. {
  532. $data = MiniExpressService::getAllImmeDelivery();
  533. util::success($data);
  534. }
  535. //即时配送
  536. /*
  537. * Array
  538. (
  539. [resultcode] => 0
  540. [resultmsg] => OK
  541. [shop_list] => Array
  542. (
  543. [0] => Array
  544. (
  545. [shopid] => 1588714266
  546. [delivery_id] => SFTC
  547. [audit_result] => 0
  548. [create_time] => 1612172838
  549. [remark] =>
  550. [delivery_name] => 顺丰同城急送
  551. )
  552. )
  553. )
  554. */
  555. public function actionGetBindAccount()
  556. {
  557. $merchant = WxOpenClass::getGhsWxInfo();
  558. $isOpen = 2;
  559. $r = miniUtil::getBindAccount($merchant, $isOpen);
  560. dd($r);
  561. }
  562. //下单 (沙箱)
  563. /**
  564. * Array
  565. * (
  566. * [resultcode] => 0
  567. * [resultmsg] => ok
  568. * [fee] => 10
  569. * [waybill_id] => test_shop_id1612365974_waybillid
  570. * [order_status] => 101
  571. * [dispatch_duration] => 300
  572. * )
  573. */
  574. public function actionCreateWaybill()
  575. {
  576. $merchant = WxOpenClass::getGhsWxInfo();
  577. $isOpen = 2;
  578. $shopId = 'test_shop_id';
  579. $shopOrderId = 'test_shop_id' . time();
  580. $appSecret = 'test_app_secrect';
  581. $data = [
  582. 'shopid' => $shopId,
  583. 'shop_order_id' => $shopOrderId,
  584. 'shop_no' => '1',
  585. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  586. 'delivery_id' => "TEST",
  587. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  588. 'sender' => [
  589. 'name' => 'test',
  590. 'city' => '厦门市',
  591. 'address' => '思明区',
  592. 'address_detail' => '软件园二期',
  593. 'phone' => '19959271111',
  594. 'lng' => 118.134343,
  595. 'lat' => 24.483566,
  596. 'coordinate_type' => 0,
  597. ],
  598. 'receiver' => [
  599. 'name' => 'test',
  600. 'city' => '厦门市',
  601. 'address' => '思明区',
  602. 'address_detail' => '软件园二期',
  603. 'phone' => '19959271111',
  604. 'lng' => 118.134343,
  605. 'lat' => 24.493566,
  606. 'coordinate_type' => 0,
  607. ],
  608. 'cargo' => [
  609. 'goods_value' => 1,
  610. 'goods_weight' => 0.1,
  611. 'cargo_first_class' => '鲜花',
  612. 'cargo_second_class' => '鲜花',
  613. ],
  614. 'order_info' => [
  615. 'order_type' => 0,
  616. ],
  617. 'shop' => [
  618. 'wxa_path' => '/shop',
  619. 'img_url' => 'http://www.baidu.com/test.png',
  620. 'goods_name' => 'test',
  621. 'goods_count' => 1,
  622. ],
  623. ];
  624. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  625. dd($r);
  626. }
  627. //获取运单数据
  628. /**
  629. * Array
  630. * (
  631. * [resultcode] => 0
  632. * [resultmsg] => ok
  633. * [order_status] => 101
  634. * [agent_info] => Array
  635. * (
  636. * )
  637. *
  638. * [waybill_id] => test_shop_id1612365974_waybillid
  639. * [rider_name] =>
  640. * [rider_phone] =>
  641. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  642. * )
  643. */
  644. public function actionGetOrder()
  645. {
  646. $shopId = 'test_shop_id';
  647. $shopOrderId = 'test_shop_id1612365974';
  648. $appSecret = 'test_app_secrect';
  649. $merchant = WxOpenClass::getGhsWxInfo();
  650. $isOpen = 2;
  651. $data = [
  652. 'shopid' => $shopId,
  653. 'shop_order_id' => $shopOrderId,
  654. 'shop_no' => '1',
  655. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  656. ];
  657. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  658. dd($r);
  659. }
  660. //沙盒 更新快递状态
  661. public function actionMockUpdateOrder()
  662. {
  663. $merchant = WxOpenClass::getGhsWxInfo();
  664. $isOpen = 2;
  665. /**
  666. * {
  667. * "shopid": "test_shop_id",
  668. * "shop_order_id": "xxxxxxxxxxx",
  669. * "waybill_id": "xxxxxxxxxxxxx",
  670. * "action_time": 12345678,
  671. * "order_status": 101,
  672. * "action_msg": "",
  673. * }
  674. */
  675. $shopId = 'test_shop_id';
  676. $shopOrderId = 'test_shop_id1612365974';
  677. $data = [
  678. 'shop_order_id' => $shopOrderId,
  679. "shopid" => $shopId,
  680. "action_time" => time(),
  681. "order_status" => 302,
  682. 'action_msg' => '状态变更',
  683. ];
  684. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  685. dd($r);
  686. }
  687. public function actionTest()
  688. {
  689. }
  690. //新增订单
  691. public function actionAddOrder()
  692. {
  693. $dada = Yii::getAlias("@vendor/dada/");
  694. require_once $dada . 'api/addOrderApi.php';
  695. require_once $dada . 'client/dadaRequestClient.php';
  696. require_once $dada . 'client/dadaResponse.php';
  697. require_once $dada . 'config/config.php';
  698. require_once $dada . 'model/orderModel.php';
  699. // isOnline 判断是否是测试环境,会有不同的域名等
  700. $isOnline = false;
  701. $sourceId = 1000000;
  702. // 初始化一个config
  703. $config = new \Config($sourceId, $isOnline);
  704. $orderModel = new \OrderModel();
  705. $orderModel->setShopNo('11047059');
  706. $orderModel->setOriginId('2018091100000002');
  707. $orderModel->setCityCode('021');
  708. $orderModel->setCargoPrice(10);
  709. $orderModel->setIsPrepay(0);
  710. $orderModel->setReceiverName('测试达达');
  711. $orderModel->setReceiverAddress('上海市崇明岛');
  712. $orderModel->setReceiverLat(31.63);
  713. $orderModel->setReceiverLng(121.41);
  714. $orderModel->setReceiverPhone('18588888888');
  715. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  716. // api主要有2个参数,一个是url, 一个是业务参数
  717. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  718. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  719. $resp = $dada_client->makeRequest();
  720. echo json_encode($resp);
  721. }
  722. //订单详情查询
  723. public function actionOrderQuery()
  724. {
  725. $dada = Yii::getAlias("@vendor/dada/");
  726. require_once $dada . 'api/OrderQueryApi.php';
  727. require_once $dada . 'client/dadaRequestClient.php';
  728. require_once $dada . 'client/dadaResponse.php';
  729. require_once $dada . 'config/config.php';
  730. require_once $dada . 'model/orderModel.php';
  731. // isOnline 判断是否是测试环境,会有不同的域名等
  732. $isOnline = false;
  733. $sourceId = 1000000;
  734. // 初始化一个config
  735. $config = new \Config($sourceId, $isOnline);
  736. $orderModel = new \OrderModel();
  737. $orderModel->setOrderId('2018091100000002');
  738. // api主要有2个参数,一个是url, 一个是业务参数
  739. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  740. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  741. $resp = $dada_client->makeRequest();
  742. echo json_encode($resp);
  743. }
  744. public function actionFocus()
  745. {
  746. $name = '花卉宝';
  747. if (getenv('YII_ENV') == 'dev') {
  748. $name = '花美灵';
  749. }
  750. $merchant = MerchantService::getByCondition(['name' => $name]);
  751. $list = wxUtil::getSubscribeUserList($merchant);
  752. dd($list);
  753. }
  754. //宝贝售出提醒 ssh 2020.1.30
  755. public function actionInform()
  756. {
  757. $merchant = MerchantService::getMerchantById(12362);
  758. $order = OrderService::getById(214810);
  759. InformAdminClass::sendComplete($order);
  760. }
  761. public function actionNotice()
  762. {
  763. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  764. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  765. echo '<pre>';
  766. print_r($data);
  767. $msg = serialize($data);
  768. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  769. }
  770. }