MerchantIntention.php 54 KB

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