MerchantIntention.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-07-18
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\system\merchant;
  11. use AdaPaySdk\AdapayTools;
  12. use app\common\model\merchant\MerchantQrcode;
  13. use app\common\repositories\merchant\apply\MerchantHaikeApplyRepository;
  14. use app\common\repositories\merchant\apply\MerchantLakalaApplyRepository;
  15. use app\common\repositories\system\attachment\AttachmentRepository;
  16. use app\controller\Rsa;
  17. use app\model\Offline\HuifuMemberEnterprise;
  18. use crmeb\services\QrcodeService;
  19. use think\App;
  20. use crmeb\basic\BaseController;
  21. use app\common\repositories\system\merchant\MerchantIntentionRepository;
  22. use think\db\Where;
  23. use think\Exception;
  24. use think\exception\ValidateException;
  25. use think\facade\Db;
  26. use Lakala\src\LakalaBoss;
  27. use think\facade\Log;
  28. class MerchantIntention extends BaseController
  29. {
  30. /**
  31. * @var MerchantIntentionRepository
  32. */
  33. protected $repository;
  34. /**
  35. * MerchantIntention constructor.
  36. * @param App $app
  37. * @param MerchantIntentionRepository $repository
  38. */
  39. public function __construct(App $app, MerchantIntentionRepository $repository)
  40. {
  41. parent::__construct($app);
  42. $this->repository = $repository;
  43. }
  44. public function lst()
  45. {
  46. [$page, $limit] = $this->getPage();
  47. $where = $this->request->params(['keyword', 'status', 'date', 'account']);
  48. return app('json')->success($this->repository->getList($where, $page, $limit));
  49. }
  50. public function form($id)
  51. {
  52. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  53. return app('json')->fail('数据不存在');
  54. return app('json')->success(formToData($this->repository->markForm($id)));
  55. }
  56. public function statusForm($id)
  57. {
  58. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  59. return app('json')->fail('数据不存在');
  60. return app('json')->success(formToData($this->repository->statusForm($id)));
  61. }
  62. public function mark($id)
  63. {
  64. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  65. return app('json')->fail('数据不存在');
  66. $data = $this->request->params([
  67. 'type','logo','mer_name','mer_short_name','addr','open_account','acc_type',
  68. 'bank_account','bank_deposit','bank_branch',
  69. 'name','phone','email','spread_account',
  70. 'card_positive_person','card_back_person','identification_valid_date_start','identification_valid_date_end','idcard_no','business_premises2','business_premises3','business_premises4','doorhead','business_license','business_addr','house_number','credit_code','haike_wx_type','haike_ali_type','haike_wx_appid','agent_apply_no'
  71. ]);
  72. if (!$this->repository->exists($id))
  73. return app('json')->fail('数据不存在');
  74. $this->repository->update($id, $data);
  75. return app('json')->success('修改成功');
  76. }
  77. public function switchStatus($id)
  78. {
  79. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  80. return app('json')->fail('数据不存在');
  81. $status = $this->request->param('status', 0) == 1 ? 1 : 2;
  82. $check_result = $this->request->param('check_result', '');
  83. $mer_id = 0;
  84. if ($status == 1){
  85. $activation_code=Db::name('merchant_intention')->where('mer_intention_id',$id)->value('activation_code');
  86. Db::name('activation_code')->where('code',$activation_code)->update(['status'=>3,'utime'=>time()]);
  87. //审核通过 创建商户
  88. $result = $this->repository->createMer($id);
  89. if ($result['code'] != 200) {
  90. return app('json')->fail($result['msg']);
  91. }
  92. $mer_id = $result['data'];
  93. /*首信易入网*/
  94. // $this -> sxyApply($id);
  95. /*首信易end*/
  96. /*汇付入网*/
  97. // $this->huihupay($id);
  98. /*汇付入网end*/
  99. }else{
  100. $activation_code=Db::name('merchant_intention')->where('mer_intention_id',$id)->value('activation_code');
  101. $mer_id=Db::name('merchant_intention')->where('mer_intention_id',$id)->value('mer_id');
  102. Db::name('activation_code')->where('code',$activation_code)->update(['status'=>3,'utime'=>time()]);
  103. }
  104. $res = $this->repository->update($id, ['status' => 3,'check_result' => $check_result, "mer_id"=>$mer_id]);
  105. if($res['code'] == 400){
  106. return app('json')->fail($res['msg']);
  107. }
  108. return app('json')->success('修改成功');
  109. }
  110. public function UpgradeToMerchant($id,$type)
  111. {
  112. try {
  113. $data=Db::name('merchant_intention')->where('mer_id',$id)->find();
  114. if($type=='wx'){
  115. $name='0001';
  116. }else{
  117. // $data['phone']='17724847560';
  118. $name='config';
  119. }
  120. // $jinjian_data=$this->jinjian_data($data);
  121. // $res=$this->repository ->UpgradeToMerchants($jinjian_data,$name);//1642668206737383
  122. $res=[
  123. 'request_id'=>'1643271204838377'//ID
  124. ];
  125. $jinjian_query=$this->repository ->incoming_select(['request_id'=>$res['request_id']],$name);//进件查询
  126. // Db::name('log')->insert(['data'=>'进件查询']);
  127. // if(!empty($jinjian_query['error_type']))
  128. // return app('json')->fail('进件失败请重新尝试--可能的原因:'.$data['error_msg']);
  129. // if($type=='wx'){
  130. // Db::name('merchant_intention')->where('mer_id',$id)->update(['hf_api_key_wx'=>$jinjian_query['live_api_key'],'app_id_wx'=>$jinjian_query['app_id_list']['0']['app_id']]);
  131. // }else{
  132. // Db::name('merchant_intention')->where('mer_id',$id)->update(['hf_api_key'=>$jinjian_query['live_api_key'],'app_id'=>$jinjian_query['app_id_list']['0']['app_id']]);
  133. // }
  134. $ruzhu_data=$this->ruzhu_data($jinjian_query,$data);
  135. //
  136. // $ruzhu=$this->repository->ruzhu($ruzhu_data,$name);
  137. // dump($ruzhu);
  138. //// $ruzhu_data['request_id']='1646545572847297';
  139. // $ruzhu=$this->repository->ruzhu_query(['request_id'=>$ruzhu_data['request_id']],$name);
  140. // dump($ruzhu);
  141. $pic=Db::name('merchant_intention')->where('mer_id',$id)->find();
  142. //
  143. //
  144. // $shenhe_data=$this->shenhe_data($pic,$name);
  145. // $shenhe_commit=$this->shenhe_commit($shenhe_data,'api_live_2d788178-808b-4d73-bd9f-17c0d09cec44');
  146. // $commit_res=$this->repository->commit_res($shenhe_commit,$name);
  147. // $commit_res=$this->repository->commit_res_query(['subApiKey'=>'api_live_2d788178-808b-4d73-bd9f-17c0d09cec44']);
  148. // dump($commit_res);
  149. $mer_id='276';
  150. $this -> repository -> huifu_create($id,1,'api_live_b3a56559-bb1a-42d0-89e2-b1d85e04a655','app_f3cba57b-15f3-4135-afda-ebe9fe3416ce',$mer_id);
  151. $this -> repository -> huifu_create($id,2,'api_live_68c25d10-2808-4042-8659-900e7b98ed1f','app_bd63b366-dbf1-4c66-97ef-a1438e9c935e',$mer_id);
  152. // $this -> repository -> huifu_create($id,1,'api_live_e266401e-24d2-456a-b0b2-9810b357590a','app_64c0ff62-75e7-470f-b45e-8758cef009ee',$mer_id);
  153. // $this -> repository -> huifu_create($id,2,'api_live_2d788178-808b-4d73-bd9f-17c0d09cec44','app_fbcc4676-42d4-44d2-af97-05c85e2deef6',$mer_id);
  154. }catch (Exception $exception){
  155. Db::name('log')->insert(['data'=>'入驻失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  156. }
  157. }
  158. public function delete($id)
  159. {
  160. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  161. return app('json')->fail('数据不存在');
  162. $this->repository->update($id, ['is_del' => 1]);
  163. return app('json')->success('删除成功');
  164. }
  165. /**
  166. * 发起海科入网
  167. * @return mixed
  168. * @author php迷途小书童
  169. * @created 2021/2/3 15:55
  170. */
  171. public function apply($id)
  172. {
  173. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  174. return app('json')->fail('数据不存在');
  175. $intention = $this->repository->getDetail(['mer_intention_id'=>$id]);
  176. $applyData = [];
  177. try {
  178. $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  179. $haikeApply = $haikeRepository->getWhere(['apply_id' => $intention['mer_intention_id'],'apply_type' => 1]);
  180. if (!$intention['merch_no']) {
  181. $applyData = ['mer_intention_id' => $id,'is_again' => 0];
  182. } else if (in_array($haikeApply->status, [1,5,6])){
  183. $applyData = ['mer_intention_id' => $id,'is_again' => 1,'merch_no' => $intention['merch_no']];
  184. } else if (in_array($haikeApply->status, [3,4,7])){
  185. $applyData = ['mer_intention_id' => $id,'is_again' => 2,'merch_no' => $intention['merch_no']];
  186. }
  187. if (empty($applyData))
  188. return app('json')->fail('当前无修改信息的条件');
  189. $return = $haikeRepository->createOrder($applyData);
  190. if ($return['code'] != 200) {
  191. return app('json')->fail($return['msg']);
  192. }
  193. } catch (\Throwable $e) {
  194. return app('json')->fail($e->getMessage());
  195. }
  196. return app('json')->success('发起申请成功');
  197. }
  198. /**
  199. * 海科入网微信业务申请
  200. * @return mixed
  201. * @author php迷途小书童
  202. * @created 2021/2/3 15:55
  203. */
  204. public function wxApply($id)
  205. {
  206. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  207. return app('json')->fail('数据不存在');
  208. try {
  209. $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  210. $return = $haikeRepository->haikeWxApply(['mer_intention_id' => $id]);
  211. if ($return['return_code'] != 200) {
  212. return app('json')->fail($return['return_msg']);
  213. }
  214. } catch (\Throwable $e) {
  215. return app('json')->fail($e->getMessage());
  216. }
  217. return app('json')->success('发起申请成功');
  218. }
  219. /**
  220. * 海科入网微信业务申请-二次认证
  221. * @return mixed
  222. * @author php迷途小书童
  223. * @created 2021/2/3 15:55
  224. */
  225. public function wxAuthApply($id)
  226. {
  227. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  228. return app('json')->fail('数据不存在');
  229. try {
  230. $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  231. $return = $haikeRepository->haikeWxAuthApply(['mer_intention_id' => $id]);
  232. if ($return['code'] != 200) {
  233. return app('json')->fail($return['msg']);
  234. }
  235. //配置微信公众号
  236. $return = $haikeRepository->haikeWxAppidConfAdd(['mer_intention_id' => $id]);
  237. if ($return['return_code'] != 200) {
  238. return app('json')->fail($return['return_msg']);
  239. }
  240. } catch (\Throwable $e) {
  241. return app('json')->fail($e->getMessage());
  242. }
  243. return app('json')->success('发起申请成功');
  244. }
  245. /**
  246. * 海科入网支付宝业务申请
  247. * @return mixed
  248. * @author php迷途小书童
  249. * @created 2021/2/3 15:55
  250. */
  251. public function aliApply($id)
  252. {
  253. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  254. return app('json')->fail('数据不存在');
  255. try {
  256. $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  257. $return = $haikeRepository->haikeAliApply(['mer_intention_id' => $id]);
  258. if ($return['return_code'] != 200) {
  259. return app('json')->fail($return['return_msg']);
  260. }
  261. } catch (\Throwable $e) {
  262. return app('json')->fail($e->getMessage());
  263. }
  264. return app('json')->success('发起申请成功');
  265. }
  266. /*详情*/
  267. public function detail($id){
  268. if (!$this->repository->getWhereCount(['mer_intention_id' => $id]))
  269. return app('json')->fail('数据不存在');
  270. $data = $this->repository->getDetail(['mer_intention_id'=>$id]);
  271. return app("json")->success("获取成功",$data);
  272. }
  273. /**
  274. * 首信易入网all
  275. * */
  276. public function sxyApplyAll(){
  277. set_time_limit(0);
  278. // $intention=Db::name("merchant_intention")
  279. // //审核通过//海科入网通过//未在首信易入网
  280. // -> where("status = 1 and sxy_declare_id = 0 and merch_no != ''")
  281. // -> field("mer_intention_id")
  282. // ->select();
  283. $intention = Db::name("declare_log") -> where("`declare` = 2") -> field("m_id") -> select();
  284. if($intention){
  285. $intention = $intention -> toArray();
  286. foreach ($intention as $key => $value){
  287. // $this -> repository -> createSXY($value['mer_intention_id']);
  288. $this -> repository -> createSXY($value['m_id']);
  289. sleep(10);
  290. }
  291. }
  292. }
  293. /**
  294. * 首信易入网
  295. * */
  296. public function sxyApply($id){
  297. $merchant=Db::name('merchant_intention')->alias('mi')->leftJoin('merchant m','m.mer_id=mi.mer_id')->where('mi.mer_intention_id',$id)->field('m.*')->find();
  298. if(!$merchant){
  299. return app('json')->fail('该入驻申请还未开店');
  300. }
  301. $result = $this -> repository -> sxyStatus($id);
  302. if($result['code']==1){
  303. return app('json')->fail('首信易正在审核');
  304. }
  305. Db::name('log')->insert(['data'=>'自动审核通过接着执行_首信易']);
  306. Db::name('log')->insert(['data'=>'商户自动审核通通过首信易入网1=='.$id,'time'=>date('Y-m-d H:i:s',time())]);
  307. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  308. return false;
  309. Db::name('log')->insert(['data'=>'商户自动审核通通过首信易入网2=='.$id,'time'=>date('Y-m-d H:i:s',time())]);
  310. $res = $this -> repository -> createSXY($id);
  311. return app('json')->success('申请已提交');
  312. }
  313. /**
  314. * @param $id
  315. * #@return int
  316. */
  317. public function huihupay($id)
  318. {
  319. $merchant=Db::name('merchant_intention')->alias('mi')->leftJoin('merchant m','m.mer_id=mi.mer_id')->where('mi.mer_intention_id',$id)->field('m.*')->find();
  320. if(!$merchant){
  321. return app('json')->fail('该入驻申请还未开店');
  322. }
  323. $merchant=Db::name('merchant_intention')->where('mer_intention_id',$id)->find();
  324. if($merchant['hf_status']==1){
  325. return app('json')->fail('汇付正在审核');
  326. }elseif ($merchant['hf_status']==2){
  327. return app('json')->fail('汇付审核已通过');
  328. }
  329. $user_group = Db::name('user')->where('uid', $merchant['uid'])->value('user_group');
  330. if ($user_group != 1) {
  331. return app('json')->fail('非消费者身份,不可调整成创客身份');
  332. }
  333. Db::name('log')->insert(['data'=>'自动审核通过接着执行_汇付']);
  334. Db::name('log')->insert(['data'=>'商户自动审核通过汇付入网1=='.$id,'time'=>date('Y-m-d H:i:s',time())]);
  335. // if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  336. // return false;
  337. Db::name('log')->insert(['data'=>'商户自动审核通过汇付入网2=='.$id,'time'=>date('Y-m-d H:i:s',time())]);
  338. //微信支付
  339. //支付宝和微信信息不在同一个账户上所以需要进行两次创建用户
  340. $res=$this -> repository -> huifu_create($id,1);// 支付宝 创建用户
  341. $res=$this -> repository -> huifu_create($id,2);// 微信 创建用户
  342. // return $id.'-----汇付创建完成';
  343. // sleep(5);
  344. // //支付宝支付
  345. // $this -> repository -> huifu_create($id,'1');
  346. return app('json')->success('申请已提交');
  347. }
  348. /**
  349. * 发起拉卡拉入网
  350. * @return mixed
  351. * @created 2021/2/5 15:55
  352. */
  353. public function lakalaApply($id)
  354. {
  355. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  356. return app('json')->fail('数据不存在');
  357. $intention = $this->repository->getDetail(['mer_intention_id'=>$id]);
  358. // try {
  359. // $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  360. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  361. if (!$intention['merch_no']) {
  362. $applyData = ['mer_intention_id' => $id,'is_again' => false];
  363. } else {
  364. $applyData = ['mer_intention_id' => $id,'is_again' => 1,'merch_no' => $intention['merch_no']];
  365. }
  366. // $return = $this->lakalaru($applyData,$id);
  367. // return app('json')->fail($applyData);
  368. $return = $lakalaRepository->createOrderlakala($applyData);
  369. return app('json')->fail($return);
  370. if ($return['code'] != 200) {
  371. return app('json')->fail($return);
  372. }
  373. // } catch (\Throwable $e) {
  374. // return app('json')->fail($e->getMessage());
  375. // }
  376. return app('json')->success("申请成功");
  377. }
  378. /**
  379. * 发起拉卡拉商户入驻
  380. * @return mixed
  381. * @created 2021/2/5 15:55
  382. */
  383. public function lakalaMerApply($id)
  384. {
  385. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
  386. return app('json')->fail('数据不存在');
  387. $intention = $this->repository->getDetail(['mer_intention_id'=>$id]);
  388. // try {
  389. // $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  390. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  391. if (!$intention['merch_no']) {
  392. $applyData = ['mer_intention_id' => $id,'is_again' => false];
  393. } else {
  394. $applyData = ['mer_intention_id' => $id,'is_again' => 1,'merch_no' => $intention['merch_no']];
  395. }
  396. // $return = $this->lakalaru($applyData,$id);
  397. // return app('json')->fail($applyData);
  398. $return = $lakalaRepository->createOrderlakala($applyData);
  399. return app('json')->success($return);
  400. // if ($return['code'] != 200) {
  401. // return app('json')->fail($return);
  402. // }
  403. // } catch (\Throwable $e) {
  404. // return app('json')->fail($e->getMessage());
  405. // }
  406. // return app('json')->success("申请成功");
  407. }
  408. /**
  409. * 手机号绑定
  410. * @param $id
  411. * @return mixed
  412. * @throws \think\db\exception\DataNotFoundException
  413. * @throws \think\db\exception\DbException
  414. * @throws \think\db\exception\ModelNotFoundException
  415. */
  416. public function lakalacheck($id){
  417. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])){
  418. return app('json')->fail('数据不存在');
  419. }
  420. // $intention = $this->repository->getDetail(['mer_intention_id'=>$id]);
  421. $params=Db::name("merchant_lakala_apply")->where("apply_id",$id)->find();
  422. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  423. $return = $lakalaRepository->createMobileMember($params);
  424. return app('json')->success($return);
  425. }
  426. /**
  427. * 企业信息认证
  428. * @param $id
  429. * @return mixed
  430. * @throws \think\db\exception\DataNotFoundException
  431. * @throws \think\db\exception\DbException
  432. * @throws \think\db\exception\ModelNotFoundException
  433. */
  434. public function createCompanyVerify($id){
  435. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])){
  436. return app('json')->fail('数据不存在');
  437. }
  438. $params=Db::name("merchant_lakala_apply")->where("apply_id",$id)->find();
  439. // MerchantIntentionApplyRepository
  440. // $intentionRepository = app()->make(MerchantIntentionRepository::class);
  441. // $intention = $intentionRepository->getOne(['mer_intention_id' => $params['apply_id']]);
  442. $intention=Db::name("merchant_intention")->where(['mer_intention_id' => $params['apply_id']])->find();
  443. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  444. $return = $lakalaRepository->createCompanyVerify($params,$intention);
  445. return app('json')->success($return);
  446. }
  447. /**
  448. * 首笔支付认证确认_对公卡
  449. * @param $id
  450. * @return mixed
  451. * @throws \think\db\exception\DataNotFoundException
  452. * @throws \think\db\exception\DbException
  453. * @throws \think\db\exception\ModelNotFoundException
  454. */
  455. public function memberBankBind($id){
  456. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])){
  457. return app('json')->fail('数据不存在');
  458. }
  459. $params=Db::name("merchant_lakala_apply")->where("apply_id",$id)->find();
  460. // MerchantIntentionApplyRepository
  461. // $intentionRepository = app()->make(MerchantIntentionRepository::class);
  462. // $intention = $intentionRepository->getOne(['mer_intention_id' => $params['apply_id']]);
  463. $intention=Db::name("merchant_intention")->where(['mer_intention_id' => $params['apply_id']])->find();
  464. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  465. $return = $lakalaRepository->memberBankBind($params,$intention);
  466. return app('json')->success($return);
  467. }
  468. /**
  469. * 开通商户
  470. * @param $id
  471. * @return mixed
  472. * @throws \think\db\exception\DataNotFoundException
  473. * @throws \think\db\exception\DbException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. */
  476. public function createMerchant($id){
  477. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])){
  478. return app('json')->fail('数据不存在');
  479. }
  480. $params=Db::name("merchant_lakala_apply")->where("apply_id",$id)->find();
  481. // MerchantIntentionApplyRepository
  482. // $intentionRepository = app()->make(MerchantIntentionRepository::class);
  483. // $intention = $intentionRepository->getOne(['mer_intention_id' => $params['apply_id']]);
  484. $intention=Db::name("merchant_intention")->where(['mer_intention_id' => $params['apply_id']])->find();
  485. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  486. $return = $lakalaRepository->createMerchant($params,$intention);
  487. return app('json')->success($return);
  488. }
  489. /**
  490. * 商户绑定
  491. */
  492. public function memberMerchantBind($id){
  493. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])){
  494. return app('json')->fail('数据不存在');
  495. }
  496. $params=Db::name("merchant_lakala_apply")->where("apply_id",$id)->find();
  497. $intention=Db::name("merchant_intention")->where(['mer_intention_id' => $params['apply_id']])->find();
  498. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  499. $return = $lakalaRepository->memberMerchantBind($params);
  500. return app('json')->success($return);
  501. }
  502. /**
  503. * 开通支付账户(URL)
  504. * @return mixed
  505. * @throws \think\db\exception\DataNotFoundException
  506. * @throws \think\db\exception\DbException
  507. * @throws \think\db\exception\ModelNotFoundException
  508. */
  509. public function payAccount($id){
  510. if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])){
  511. return app('json')->fail('数据不存在');
  512. }
  513. $params=Db::name("merchant_lakala_apply")->where("apply_id",$id)->find();
  514. $lakalaRepository = app()->make(MerchantLakalaApplyRepository::class);
  515. $return = $lakalaRepository->payAccount($params);
  516. return app('json')->success($return);
  517. }
  518. // public function lakalacheck($id){
  519. //// $ids = Db::name("store")->where(['id'=>$ids])->find();
  520. // $ids = $this->repository->getDetail(['mer_intention_id'=>$id]);
  521. // if($ids['mer_intention_id']){
  522. // //查询拉卡拉进件
  523. // $lakalaBoss = LakalaBoss::getInstance();
  524. // $result = $lakalaBoss->selectStore($ids['mer_intention_id'],$ids['request_id']);
  525. // if($result['code'] == 0){
  526. // if($result['data']['status'] == 'S'){
  527. // return app('json')->success('开户成功!');
  528. // }elseif($result['data']['status'] == 'F'){
  529. // return app('json')->fail("开户失败!");
  530. // }elseif($result['data']['status'] == 'P'){
  531. // return app('json')->fail("开户处理中!");
  532. // }
  533. // }else{
  534. // return app('json')->fail($result['message']);
  535. // }
  536. // }
  537. // return app('json')->fail("非法操作!");
  538. // }
  539. public function getQrcodeList(){
  540. [$page, $limit] = $this->getPage();
  541. $params = $this->request->params(['status', 'account']);
  542. if(isset($params['account']) && $params['account'] != ''){
  543. $list = Db::name("MerchantQrcode")
  544. -> alias("qr")
  545. -> join("Merchant mer","qr.mer_id = mer.mer_id")
  546. -> where("mer.mer_phone",$params['account'])
  547. -> field("qr.*")
  548. -> find();
  549. if(!$list) return app('json')->fail('查无结果');
  550. $list = [$list];
  551. $count = 1;
  552. }else{
  553. switch ($params['status']){
  554. case "3"://未绑定二维码
  555. $list = Db::name('MerchantQrcode') -> where("uid",0) -> where("mer_id",0) -> page($page,$limit) -> select();
  556. $count = Db::name('MerchantQrcode') -> where("uid",0) -> where("mer_id",0) -> count();
  557. break;
  558. case "2"://申请中商户二维码
  559. $list = Db::name('MerchantQrcode') -> where("uid","<>",0) -> where("mer_id",0) -> page($page,$limit) -> select();
  560. $count = Db::name('MerchantQrcode') -> where("uid","<>",0) -> where("mer_id",0) -> count();
  561. break;
  562. case "1"://已绑定二维码
  563. $list = Db::name('MerchantQrcode') -> where("uid","<>",0) -> where("mer_id","<>",0) -> page($page,$limit) -> select();
  564. $count = Db::name('MerchantQrcode') -> where("uid","<>",0) -> where("mer_id","<>",0) -> count();
  565. break;
  566. default:
  567. $list = Db::name('MerchantQrcode') -> page($page,$limit) -> select();
  568. $count = Db::name('MerchantQrcode') -> count();
  569. break;
  570. }
  571. if($list){
  572. $list = $list -> toArray();
  573. }
  574. }
  575. if(!$list) return app('json')->fail('查无结果');
  576. foreach ($list as $key => $value){
  577. $list[$key]['status'] = 0;
  578. $list[$key]['mer_name'] = '';
  579. if($value['uid'] != 0 && $value['mer_id'] != 0){
  580. $list[$key]['status'] = 1;//审核通过
  581. $list[$key]['mer_name'] = Db::name("merchant")->where(['mer_id' => $value['mer_id']])->value('mer_name');
  582. }
  583. if($value['uid'] != 0 && $value['mer_id'] == 0){
  584. $list[$key]['status'] = 2;//申请中
  585. $list[$key]['mer_name'] = Db::name("merchant_intention")->where(['uid' => $value['uid']])->value('mer_name');
  586. }
  587. }
  588. $return['count'] = $count;
  589. $return['list'] = $list;
  590. return app('json')->success($return);
  591. }
  592. /**
  593. * @remarks 检索渠道商手机号是否存在 返回 uid
  594. * @author Tang
  595. * @created 2021/8/30 11:32
  596. */
  597. public function search_Channel()
  598. {
  599. $phone = $this->request->params(['phone']);
  600. if(!$phone){
  601. return app('json')->fail('请输入要检索手机号码');
  602. }
  603. $uid=Db::name('user')
  604. ->alias('u')
  605. ->where('u.phone',$phone['phone'])
  606. ->where('u_a.identity',6)
  607. ->rightJoin('user_agent u_a','u.uid = u_a.user_id')
  608. ->field('u_a.id,u.uid')
  609. ->find();
  610. if($uid){
  611. return app('json')->success($uid['uid']);
  612. }else{
  613. return app('json')->fail('查无结果');
  614. }
  615. }
  616. public function createQrcode(){
  617. $num = $this->request->params(['num']);
  618. $phone = $this->request->params(['phone']);
  619. // $uid = $this->request->params(['uid']);
  620. // if(!$uid){
  621. // return app('json')->fail('请检查参数');
  622. // }
  623. $uid = 0;
  624. if(!empty($phone['phone'])){
  625. $qudao=Db::name('user')
  626. ->alias('u')
  627. ->where('u.phone',$phone['phone'])
  628. ->where('u_a.identity',6)
  629. ->rightJoin('user_agent u_a','u.uid = u_a.user_id')
  630. ->field('u_a.id,u.uid')
  631. ->find();
  632. if(!$qudao) {
  633. return app('json')->fail('此运营商不存在');
  634. }
  635. $uid = $qudao['uid'];
  636. }
  637. $max = $num['num'] <= 100 ? $num['num'] : 100;
  638. $siteUrl = systemConfig('site_url');
  639. $attachmentRepository = app()->make(AttachmentRepository::class);
  640. $urlCode = [];
  641. $codeInsert = [];
  642. $show_src_array = [];
  643. for($i = 0;$i < $max;$i++){
  644. $id = $this -> getNewQrcodeId();
  645. $name = "offlinepay_".$id.".jpg";
  646. $codeUrl = set_http_type(rtrim($siteUrl, '/') .'/offlinepay/index.html?id=' . $id, request()->isSsl() ? 0 : 1);//二维码链接
  647. $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name);
  648. if (!is_string($imageInfo)){
  649. $imageInfo['dir'] = path_to_url($imageInfo['dir']);
  650. if (strpos($imageInfo['dir'], 'http') === false) $imageInfo['dir'] = request()->domain() . $imageInfo['dir'];
  651. $attachmentRepository->create(systemConfig('upload_type') ?: 1, 0, 0, [
  652. 'attachment_category_id' => 0,
  653. 'attachment_name' => $imageInfo['name'],
  654. 'attachment_src' => $imageInfo['dir']
  655. ]);
  656. $show_src = $this -> show_src($imageInfo['dir'],$id);
  657. if(!empty($show_src)){
  658. $codeInsert[] = [
  659. 'uid'=>0,
  660. 'mer_id' =>0,
  661. 'code_id'=>$id,
  662. 'qrcode_src' => $imageInfo['dir'],
  663. 'show_src' => $show_src,
  664. 'user_id'=>$uid
  665. ];
  666. $urlCode[] = $imageInfo['dir'];
  667. $show_src_array[]=$show_src;
  668. }
  669. }
  670. unset($imageInfo);
  671. }
  672. Db::name('MerchantQrcode') -> insertAll($codeInsert);
  673. $zip = $this->addzip($show_src_array,$phone['phone']);
  674. return app('json') -> success(
  675. [
  676. 'num'=>count($urlCode),
  677. 'zip'=>$zip
  678. ]
  679. );
  680. }
  681. /**
  682. * 获取唯一id号
  683. */
  684. public function getNewQrcodeId()
  685. {
  686. list($msec, $sec) = explode(' ', microtime());
  687. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  688. $id = $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
  689. return $id;
  690. }
  691. /**
  692. * 二维码美化
  693. * */
  694. public function show_src($qrcode,$id)
  695. {
  696. $siteUrl = systemConfig('site_url');
  697. $uploadType = (int)systemConfig('upload_type') ?: 1;
  698. $resWap = true;
  699. $spreadBanner = systemConfig('show_qrcode');
  700. $attachmentRepository = app()->make(AttachmentRepository::class);
  701. //检测远程文件是否存在
  702. if (isset($qrcode) && strstr($qrcode, 'http') !== false && curl_file_exist($qrcode) === false) {
  703. $qrcode = null;
  704. }
  705. if (!$qrcode) {
  706. return false;
  707. } else $urlCode = $qrcode;
  708. $siteUrl = set_http_type($siteUrl, request()->isSsl() ? 0 : 1);
  709. $filelink = [
  710. 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  711. 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  712. ];
  713. if (!file_exists($filelink['Bold'])) throw new ValidateException('缺少字体文件Bold');
  714. if (!file_exists($filelink['Normal'])) throw new ValidateException('缺少字体文件Normal');
  715. $posterInfo = '收款码生成失败:(';
  716. $config = array(
  717. 'image' => array(
  718. array(
  719. 'url' => $urlCode, //二维码资源
  720. 'stream' => 0,
  721. 'left' => 182,
  722. 'top' => 505,
  723. 'right' => 0,
  724. 'bottom' => 0,
  725. 'width' => 581,
  726. 'height' => 581,
  727. 'opacity' => 100
  728. )
  729. ),
  730. 'text' => array(
  731. array(
  732. 'text' => $id,
  733. 'left' => 250,
  734. 'top' => 1200,
  735. 'fontPath' => $filelink['Bold'], //字体文件
  736. 'fontSize' => 32, //字号
  737. 'fontColor' => '40,40,40', //字体颜色
  738. 'angle' => 0,
  739. )
  740. ),
  741. 'background' => $spreadBanner
  742. );
  743. $resWap = $resWap && $posterInfo = setSharePoster($config, 'wap/spread/poster');
  744. if (!is_array($posterInfo)) throw new ValidateException('收款码生成失败');
  745. $posterInfo['dir'] = path_to_url($posterInfo['dir']);
  746. if (strpos($posterInfo['dir'], 'http') === false) $posterInfo['dir'] = request()->domain() . $posterInfo['dir'];
  747. $attachmentRepository->create($uploadType, 0, 0, [
  748. 'attachment_category_id' => 0,
  749. 'attachment_name' => $posterInfo['name'],
  750. 'attachment_src' => $posterInfo['dir']
  751. ]);
  752. if ($resWap) {
  753. if ($posterInfo['image_type'] == 1)
  754. $wap_poster = rtrim($siteUrl, '/') . $posterInfo['thumb_path'];
  755. else
  756. $wap_poster = set_http_type($posterInfo['thumb_path'], 1);
  757. }
  758. return $wap_poster ?? '';
  759. }
  760. //二维码打包start
  761. /**
  762. * 将优化后的二维码添加到压缩包
  763. */
  764. public function addzip($show_src,$phone)
  765. {
  766. $tmpDir = './public/zip/'; //
  767. if (!file_exists($tmpDir)) {
  768. //创建文件夹
  769. mkdir($tmpDir, 0777, true);
  770. }
  771. // $phone=Db::name('user_agent')
  772. // ->where('u_a.user_id',$uid)
  773. // ->alias('u_a')
  774. // ->leftJoin('user u','u_a.user_id=u.uid')
  775. // ->field('u.phone')
  776. // ->find();
  777. $zipName = date('YmdHis') . mt_rand(1000, 9999) . '.zip'; // 压缩包文件名
  778. if($phone > 0){
  779. $rend=md5(mt_rand(100000000, 999999999));
  780. $zipName = $phone . '_' . $rend . '.zip'; // 压缩包文件名
  781. }
  782. $zipNameUrl = $tmpDir . $zipName; // 文件路径
  783. //生成文件
  784. $zip = new \ZipArchive();
  785. if ($zip->open($zipNameUrl, \ZipArchive::OVERWRITE) !== true) {
  786. //OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在
  787. if ($zip->open($zipNameUrl, \ZipArchive::CREATE) !== true) {
  788. // 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
  789. return '下载失败,文件夹不存在';
  790. }
  791. }
  792. foreach ($show_src as $file) {
  793. //判断图片是否存在
  794. $isFile = $this->checkFileExists($file);
  795. if (!$isFile) {
  796. continue;
  797. }
  798. //抓取图片内容
  799. $fileContent = file_get_contents($file);
  800. //添加图片
  801. $zip->addFromString(basename($file), $fileContent);
  802. }
  803. // 关闭
  804. $zip->close();
  805. $qrcodeData=[
  806. 'url'=>'http://app.bjtdba.com/zip/'.$zipName,
  807. 'ctime'=>time()
  808. ];
  809. Db::name('qrcode_zip') -> insert($qrcodeData);
  810. return $qrcodeData['url'];
  811. }
  812. /**
  813. * 判断文件是否存在,支持本地及远程文件
  814. * @param String $file 文件路径
  815. * @return Boolean
  816. */
  817. private function checkFileExists($file)
  818. {
  819. // 远程文件
  820. if (strtolower(substr($file, 0, 5)) == 'https') {
  821. // 远程文件
  822. $header = get_headers($file, true);
  823. return isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'));
  824. } elseif (strtolower(substr($file, 0, 4)) == 'http') {
  825. // 远程文件
  826. $header = get_headers($file, true);
  827. return isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'));
  828. } else {
  829. // 本地文件
  830. return file_exists($file);
  831. }
  832. }
  833. //二维码打包 end
  834. public function notify($type)
  835. {
  836. $post=$this->request->param();
  837. Db::name("log")->insert(array('data'=>'【异步接受到的参数】'.json_encode($post),));//日志记录
  838. $post_data_str = isset($post['data']) ? $post['data']: '';
  839. $post_sign_str = isset($post['sign']) ? $post['sign']: '';
  840. # 先校验签名和返回的数据的签名的数据是否一致
  841. $adapay_tools=new AdapayTools();
  842. if ($post['appId'] == 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0'){
  843. AdapayTools::setRsaPrivateKey('MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKvkKGN19wxH9Uusx8gXnt89oYbgvIRkzO2pD0nzSF/MS65m2j5DgKMG5lryL6bfco2p9syoxKI7IE9pLFtFTyI477cNoUsvWiIYikx5uKz0CDdBcR8AAapfrs5XKgJMcogulqDm4/7QUDuQJoATdvEpA6yfiaW2EqSnMpvZKsdFAgMBAAECgYAgmVOjkUK6HIeDw4/b/cbOlbSljMeT4D4RMIfKwY3PRUJxH+Zx+oFR6cQUKWwqHKRwA3Tf2X35OndlOBAGez2Hc1M08brGSlCB/Ze654mOP5H+bImKfmWQxJiVbbY4ef6msgNAp+FicWLvo6WDuymmP7gvoQbC5E90tRKDCvyawQJBANy/GaYU209Dikbd6E2rWKaS9dgx9f/wZOqmUMUzsDicMO4nK1qojyEm8inkoSRyzv0vLXqD/j/buhE4FjO/YbECQQDHV66K4NKNvuKAbI0NNXothxe2PS6lJrBU5QWgt4Q6CsQ8v+WyFq9AUjEahN11Evm2DCnEBddZKmSctZTgry/VAkAgCEMKjKA+Ykige/cHvkOA+HZgRu+xkgqy2iuCUjvSGygmhtyNrUQHxYUCe0C+70IGD2CEFL9COPpJIWBnZfAhAkATbV0qVbzPaaIDaBDbD7Ini7no3c+U8s9Ohr9kqV3uliwHy5/kGkfcGeaFMhuvFDlX35mWbAdPvkzt5NhsiUY9AkBNdE3yUz+f7A92oZr4bHX7r5gyUTumRiBYyiJ8dgMl6lT8OpQZpBxdswyWg2nkmPoCjoASZx8LoCBhsK4SBcfz');
  844. }else{
  845. AdapayTools::setRsaPrivateKey('MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALFOkwRKx2HKMpAL7LUb755cIS7mleort++Rkl25tJMJCf9Ezeyg4xwLBN6RQsLERTAzRKc/EUtxm4/9rzDzvNZ4BegEI8mXWBUrgpn7e1ar8Ek8IRPdXLrozuld9cv56R3yB/Yta0R+kmgCfn2C5V+xtM6njimkOStvdK5cNwqFAgMBAAECgYA5pn+87IeJr1Hjbk0n0g6GYhRUCJuECXUEC0QY/3HMQSsj+f4uy10s2BRcPcUESQbqFjFjY+k+q5DWL7kP5KBoXGnFyflAyRhWGTkSC3VhGixh6ro3EcUJSrFDjGaThGaPrc8Zfcp5JhL5Thi0GaBXSnRH1Cmn4h8gkAEJxIM7PQJBAOq2+oVPtqkj99YRs0eewkZAM7bKRzSwI7OFU6YWsCYVkqNE7Lr3KKGekehuWwkOvrCBR+NEGQfAb557g2CHmzMCQQDBYtgQ5wvl9fD8BWAVKuPoxoleH+9wUQ65Rnt/Ebkx+g8kP37JRun81duLDULTKr/3ak42goE00TfnfeXl0gNnAkA0wuUVypF4/AjeKiRu2RU6zXvSfy36fg3IcRQYpcj7BqZr5TaB4MVVb1vFL+lu482hx63tPIWT5IIy0fj6XgFZAkBinlKLRBgIPISZMPCPuuCg22ZADs8fGucEStI9ub8Uom3IUW0JndVDb5fW8HtMjrd4p8ic+a6ETdFRhx2PNqsvAkAzDvlve56sZnLYx9t/MPkJTK3ZhgVETS0H2FUyJGVOSfjv68bNsUshyPfzJrdbCeLzjMLq8TpyOmiIUAeQ5YCX');
  846. }
  847. $sign_flag = $adapay_tools->verifySign($post_data_str, $post_sign_str);
  848. $post_data_str=json_decode($post_data_str,true);
  849. if ($sign_flag){
  850. switch ($type){
  851. case "pay":
  852. try {
  853. Db::name("log")->insert(array('data'=>'【验签通过-支付】:时间:'.date('Y-m-d H:i:s',time()),));//日志记录
  854. }catch (Exception $exception){
  855. return app('json')->fail('错误2');
  856. }
  857. break;
  858. case "crate_merber_enterprise":
  859. Db::name("log")->insert(array('data'=>'【汇付创建企业用户】: 验签通过:时间'.date('Y-m-d H:i:s',time())));//日志记录
  860. try {
  861. if($post_data_str['audit_state']=='D'|| $post_data_str['audit_state']=='E'){
  862. Db::name("log")->insert(array('data'=>'状态判断完了'));//日志记录
  863. $id=Db::name("hf_user_order")->where('order_no',$post_data_str['order_no'])->value('mer_intention_id');
  864. $mer_id=Db::name("hf_user_order")->alias('huo')->leftJoin('merchant_intention mi','huo.mer_intention_id=mi.mer_intention_id')->where('order_no',$post_data_str['order_no'])->value('mi.mer_id');
  865. $checkMerchat=Db::name('merchant')
  866. ->where('mer_id',$mer_id)
  867. ->find();
  868. $insert = [
  869. [
  870. 'mer_id' => $checkMerchat['mer_id'],
  871. 'type' => 1,
  872. 'member_id' => $checkMerchat['hf_member_id']
  873. ],
  874. [
  875. 'mer_id' => $checkMerchat['mer_id'],
  876. 'type' => 2,
  877. 'member_id' => $checkMerchat['hf_member_id_wx']
  878. ],
  879. [
  880. 'mer_id' => $checkMerchat['mer_id'],
  881. 'type' => 3,
  882. 'member_id' => $post_data_str['member_id']
  883. ],
  884. ];
  885. Db::name('merchant_member')->where('mer_id', $mer_id)->insertAll($insert);
  886. }else{
  887. $id=Db::name("hf_user_order")->where('order_no',$post_data_str['order_no'])->value('mer_intention_id');
  888. Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['check_result'=>$post_data_str['audit_desc'],'status'=>3,'hf_status'=>3]);
  889. }
  890. }catch (Exception $e){
  891. Db::name("log")->insert(array('data'=>'执行错误————'.$e->getMessage()));
  892. }
  893. break;
  894. case "ruzhu":
  895. // Db::name('');
  896. }
  897. # 业务方自己的逻辑
  898. }
  899. }
  900. /**
  901. * 商户进件需要的数据
  902. */
  903. public function jinjian_data($data)
  904. {//license_code mer_start_valid_date mer_valid_date
  905. if($data['identification_valid_date_end']=='forever'){
  906. $data['identification_valid_date_end']='20991231';
  907. }
  908. if($data['acc_type']=='10A'){
  909. $bank_acct_type=1;
  910. }else if ($data['acc_type']=='10B'){
  911. $bank_acct_type=2;
  912. }
  913. $license_code='';
  914. $mer_start_valid_date='';
  915. $mer_valid_date='';
  916. if($data['type']==1||$data['type']==2){
  917. $type='1';
  918. $license_code=$data['credit_code'];
  919. $mer_start_valid_date=date('Ymd',strtotime($data['merc_start_time']));
  920. if($data['merc_end_time']=='forever'){
  921. $mer_valid_date='20991231';
  922. }else{
  923. $mer_valid_date=date('Ymd',strtotime($data['merc_end_time']));
  924. }
  925. }else{
  926. $type=2;
  927. }
  928. $bank_code=Db::name('hf_bank_code')->whereLike('name','%'.$data['bank_deposit'].'%')->value('code');
  929. if(!$bank_code){
  930. Db::name('merchant_intention')->where('mer_intention_id',$data['mer_intention_id'])->update(['status'=>2,'check_result'=>'银行卡开户行填写不正确']);
  931. return app('json')->fail('银行卡开户行填写不正确');
  932. }
  933. // $data['phone']='17354256998';
  934. $returndata=[
  935. 'request_id'=>time().rand(111111,999999),
  936. 'usr_phone'=>$data['phone'],
  937. 'cont_name'=>$data['name'],
  938. 'cont_phone'=>$data['phone'],
  939. 'customer_email'=>$data['email'],
  940. 'mer_name'=>$data['mer_name'],
  941. 'mer_short_name'=>$data['mer_short_name'],
  942. 'reg_addr'=>$data['addr'],
  943. 'cust_addr'=>$data['addr'],
  944. 'cust_tel'=>$data['phone'],
  945. 'legal_name'=>$data['name'],
  946. 'legal_type'=>0,
  947. 'legal_idno'=>$data['idcard_no'],
  948. 'legal_mp'=>$data['phone'],
  949. 'legal_start_cert_id_expires'=>date('Ymd',strtotime($data['identification_valid_date_start'])),
  950. 'legal_id_expires'=>date('Ymd',strtotime($data['identification_valid_date_end'])),
  951. 'card_id_mask'=>$data['bank_account'],
  952. 'card_name'=>$data['bank_deposit'],
  953. 'bank_acct_type'=>$bank_acct_type,
  954. 'bank_code'=>$bank_code,
  955. 'prov_code'=>$this->getHfAddress($data['province_id'],'province'),//省份编码 (省市编码),
  956. 'area_code'=>$this->getHfAddress($data['city_id'],'city'),//地区编码 (省市编码)
  957. 'license_code'=>$license_code,
  958. 'mer_valid_date'=>$mer_valid_date,
  959. 'mer_start_valid_date'=>$mer_start_valid_date,
  960. 'entry_mer_type'=>$type,
  961. 'rsa_public_key'=>'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxTpMESsdhyjKQC+y1G++eXCEu5pXqK7fvkZJdubSTCQn/RM3soOMcCwTekULCxEUwM0SnPxFLcZuP/a8w87zWeAXoBCPJl1gVK4KZ+3tWq/BJPCET3Vy66M7pXfXL+ekd8gf2LWtEfpJoAn59guVfsbTOp44ppDkrb3SuXDcKhQIDAQAB'
  962. ];
  963. return $returndata;
  964. }
  965. public function ruzhu_data($data,$mer_data)
  966. {
  967. $config=[
  968. 'wx_lite'=> [
  969. 'appid'=> 'wx9082e5ac2fdb513f'
  970. ],
  971. 'wx_pub'=>[
  972. // 'appid'=>'wx66f5f8def2b755da',//天地博爱
  973. 'appid'=>'wx9909df446471d46b',//天地博爱网络
  974. 'path'=>'https://app.bjtdba.com/'
  975. ],
  976. 'wx_scan'=>'',
  977. 'alipay'=>'',
  978. 'alipay_wap'=>'',
  979. 'alipay_lite'=>'',
  980. 'alipay_qr'=>'',
  981. 'alipay_pub'=>'',
  982. 'alipay_scan'=>''
  983. ];
  984. if($mer_data['type']==1){
  985. $mer_type=3;
  986. }elseif ($mer_data['type']==2){
  987. $mer_type=5;
  988. }else{
  989. $mer_type=8;
  990. }
  991. $request_id=time().rand(111111,999999);
  992. $return_data=[
  993. 'sub_api_key'=>$data['live_api_key'],
  994. 'fee_type'=>'02',
  995. 'app_id'=>$data['app_id_list']['0']['app_id'],
  996. 'request_id'=>$request_id,
  997. 'wx_category'=>'756',
  998. 'alipay_category'=>'2015091000052157',
  999. 'cls_id'=>'5331',
  1000. 'model_type'=>'1',
  1001. 'mer_type'=>$mer_type,
  1002. 'province_code'=>$this->getHfAddress_ruzhu($mer_data['province_id'],'province'),//省份编码 (省市编码),
  1003. 'city_code'=>$this->getHfAddress_ruzhu($mer_data['city_id'],'city'),//省份编码 (省市编码),
  1004. 'district_code'=>$this->getHfAddress_ruzhu($mer_data['province_id'],'area'),//省份编码 (省市编码),
  1005. // 'add_value_list'=>'{"alipay":"","alipay_wap":"","alipay_lite":"","alipay_qr":"","alipay_scan":""}',
  1006. 'add_value_list'=>json_encode($config),
  1007. 'notify_url'=>env('APP_URL').'/sys/HuiPay/notify_url/'.'ruzhu'
  1008. ];
  1009. return $return_data;
  1010. }
  1011. public function getHfAddress($id,$type){
  1012. if($type == 'province'){
  1013. $res = Db::name("user_province")
  1014. ->where(['province_id' => $id])
  1015. ->field('province_code,short_name')
  1016. ->find();
  1017. $code = $res['province_code'];
  1018. $check = Db::name("hf_business_address") -> where('code',$code) -> find();
  1019. if(!$check){
  1020. $code = Db::name("hf_business_address") -> where("province like '%".$res['short_name']."%'") -> value('code');
  1021. }
  1022. return $code;
  1023. }
  1024. if($type == 'city'){
  1025. $res = Db::name("user_city")
  1026. ->where(['city_id' => $id])
  1027. ->field('city_code,short_name')
  1028. ->find();
  1029. $code = $res['city_code'];
  1030. $check = Db::name("hf_business_address") -> where('code',$code) -> find();
  1031. if(!$check){
  1032. $code = Db::name("hf_business_address") -> where("city like '%".$res['short_name']."%'") -> value('code');
  1033. }
  1034. return $code;
  1035. }
  1036. if($type == 'area'){
  1037. $res = Db::name("user_area")
  1038. ->where(['area_id' => $id])
  1039. ->field('area_code,short_name')
  1040. ->find();
  1041. $code = $res['area_code'];
  1042. $check = Db::name("hf_business_address") -> where('code',$code) -> find();
  1043. if(!$check){
  1044. $code = Db::name("hf_business_address") -> where("area like '%".$res['short_name']."%'") -> value('code');
  1045. }
  1046. return $code;
  1047. }
  1048. return '';
  1049. }
  1050. public function getHfAddress_ruzhu($id,$type){
  1051. if($type == 'province'){
  1052. $res = Db::name("user_province")
  1053. ->where(['province_id' => $id])
  1054. ->field('province_code,short_name')
  1055. ->find();
  1056. $code = $res['province_code'];
  1057. $check = Db::name("hf_business_address_ruzhu") -> where('code',$code) -> find();
  1058. if(!$check){
  1059. $code = Db::name("hf_business_address_ruzhu") -> where("province like '%".$res['short_name']."%'") -> value('code');
  1060. }
  1061. return $code;
  1062. }
  1063. if($type == 'city'){
  1064. $res = Db::name("user_city")
  1065. ->where(['city_id' => $id])
  1066. ->field('city_code,short_name')
  1067. ->find();
  1068. $code = $res['city_code'];
  1069. $check = Db::name("hf_business_address_ruzhu") -> where('code',$code) -> find();
  1070. if(!$check){
  1071. $code = Db::name("hf_business_address_ruzhu") -> where("city like '%".$res['short_name']."%'") -> value('code');
  1072. }
  1073. return $code;
  1074. }
  1075. if($type == 'area'){
  1076. $res = Db::name("user_area")
  1077. ->where(['area_id' => $id])
  1078. ->field('area_code,short_name')
  1079. ->find();
  1080. $code = $res['area_code'];
  1081. $check = Db::name("hf_business_address_ruzhu") -> where('code',$code) -> find();
  1082. if(!$check){
  1083. $code = Db::name("hf_business_address_ruzhu") -> where("area like '%".$res['short_name']."%'") -> value('code');
  1084. }
  1085. return $code;
  1086. }
  1087. return '';
  1088. }
  1089. //图片类型,01:三证合一码,02:法人/小微负责人身份证正面,03:法人/小微负责人身份证反面,04:门店,05:开户许可证/小微负责人银行卡正面照,06:股东身份证正面,07:股东身份证反面,08:结算账号开户证明,09:网站截图,10:行业资质文件,11:icp备案许可证明或者许可证编码,12:租赁合同,13:交易测试记录,14:业务场景证明材料
  1090. public function shenhe_data($data,$name)
  1091. {
  1092. $return_data=[];
  1093. if($name=='0001'){
  1094. $hf_api_key=$data['hf_api_key_wx'];
  1095. }else{
  1096. $hf_api_key=$data['hf_api_key'];
  1097. }
  1098. if($data['type']==3){
  1099. }else{
  1100. $shenhedata=[
  1101. 'subApiKey'=>$hf_api_key,
  1102. 'file'=>$this->imgToBaes64($data['business_license']),
  1103. 'fileType'=>'01'
  1104. ];
  1105. $return_data[]=$this->repository->merProfilePictures($shenhedata,$name);
  1106. $shenhedata=[
  1107. 'subApiKey'=>$hf_api_key,
  1108. 'file'=>$this->imgToBaes64($data['card_positive_person']),
  1109. 'fileType'=>'02'
  1110. ];
  1111. $return_data[]=$this->repository->merProfilePictures($shenhedata,$name);
  1112. $shenhedata=[
  1113. 'subApiKey'=>$hf_api_key,
  1114. 'file'=>$this->imgToBaes64($data['card_back_person']),
  1115. 'fileType'=>'03'
  1116. ];
  1117. $return_data[]=$this->repository->merProfilePictures($shenhedata,$name);
  1118. $shenhedata=[
  1119. 'subApiKey'=>$hf_api_key,
  1120. 'file'=>$this->imgToBaes64('https://88yx.xyz/qqh/uploads/20220314142841969.jpg'),
  1121. // 'file'=>$this->($data['business_license']),
  1122. 'fileType'=>'04'
  1123. ];
  1124. $return_data[]=$this->repository->merProfilePictures($shenhedata,$name);
  1125. $shenhedata=[
  1126. 'subApiKey'=>$hf_api_key,
  1127. // 'file'=>$data['business_license'],
  1128. 'file'=>$this->imgToBaes64('http://88yx.xyz/qqh/uploads/20220127154252626.jpg'),
  1129. 'fileType'=>'04'
  1130. ];
  1131. $return_data[]=$this->repository->merProfilePictures($shenhedata,$name);
  1132. $shenhedata=[
  1133. 'subApiKey'=>$hf_api_key,
  1134. 'file'=>$this->imgToBaes64($data['open_account']),
  1135. 'fileType'=>'05'
  1136. ];
  1137. $return_data[]=$this->repository->merProfilePictures($shenhedata,$name);
  1138. }
  1139. return $return_data;
  1140. }
  1141. function imgToBaes64($url)
  1142. {
  1143. $imgInfo = getimagesize($url);
  1144. return 'data:'.$imgInfo['mime'].';base64,'.base64_encode(file_get_contents($url));
  1145. }
  1146. public function shenhe_commit($data,$api_key)
  1147. {
  1148. $return_data=[
  1149. 'socialCreditCodeId'=>$data['0']['pic_id'],
  1150. 'legalCertIdFrontId'=>$data['1']['pic_id'],
  1151. 'legalCertIdBackId'=>$data['2']['pic_id'],
  1152. 'storeId'=>$data['3']['pic_id'].'|'.$data['4']['pic_id'],
  1153. 'accountOpeningPermitId'=>$data['5']['pic_id'],
  1154. 'subApiKey'=>$api_key
  1155. ];
  1156. return $return_data;
  1157. }
  1158. public function huiFuSettleIn()
  1159. {
  1160. $mer_id = $this->request->param('mer_id', 0);
  1161. $merchant=Db::name('merchant_intention')
  1162. ->alias('mi')
  1163. ->Join('merchant m','m.mer_id=mi.mer_id')
  1164. ->where('mi.hf_status',0)
  1165. ->when($mer_id != 0,function ($query) use ($mer_id){
  1166. $query -> where('m.mer_id',$mer_id);
  1167. })
  1168. ->field('mi.mer_intention_id,m.mer_id,mi.hf_status,mi.idcard_no,mi.bank_account')
  1169. // ->limit(5)
  1170. -> select()
  1171. ->toArray();
  1172. foreach ($merchant as $row){
  1173. if($row['idcard_no'] == '') continue;
  1174. if($row['bank_account'] == '') continue;
  1175. $res = $this -> repository -> huifu_create($row['mer_intention_id'],3,'','',$row['mer_id']);// 微信 创建用户
  1176. log::info($res);
  1177. }
  1178. return app('json')->success("运行结束");
  1179. }
  1180. }