TestController.php 38 KB

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