TestController.php 41 KB

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