TestController.php 39 KB

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