| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- /**
- * @package merchant
- *
- * @author Qinii
- * @day 2020-07-18
- *
- *
- */
- namespace app\controller\api\store\merchant;
- use app\common\repositories\merchant\apply\MerchantHaikeApplyRepository;
- use app\common\repositories\system\config\ConfigValueRepository;
- use think\App;
- use crmeb\basic\BaseController;
- use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
- use think\db\Where;
- use think\Exception;
- use think\facade\Cache;
- use think\facade\Db;
- use think\facade\Log;
- use app\controller\admin\system\merchant\MerchantIntention as merchant;
- class MerchantIntention extends BaseController
- {
- protected $repository;
- protected $userInfo;
- /**
- * @var \Redis
- */
- protected $redis;
- public function __construct(App $app, repository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
- $this->redis = Cache::store('redis')->handler();
- }
- /*申请创建*/
- public function create()
- {
- makeLock()->lock();
- try {
- $code_id = $this->request->params(['code_id']);
- if(isset($code_id['code_id']) && $code_id['code_id'] != ''){
- $checkQrcode = Db::name("MerchantQrcode") -> where('code_id',$code_id['code_id']) -> find();
- if(!$checkQrcode)throw new Exception('二维码无效');
- //用户id不等于0 并且用户id不等与提交的用户id。二维码无效
- if($checkQrcode['uid'] != 0 && $checkQrcode['uid'] != $this->userInfo->uid)throw new Exception('二维码无效');
- }
- $mer_intention_id = 0;
- /*判断用户是否是代理/商户身份*/
- $user =$this->repository->getIdentity($this->userInfo->uid);
- // 1,2,3,4,5
- if(in_array($user['identity'],[4])){
- throw new Exception('已是商户或者代理,不能继续申请');
- }
- $real_name = $this->repository->real($this->userInfo->uid);
- if($real_name == 0) {
- throw new Exception('请先实名认证');
- }
- $find = Db::name("merchant_intention")
- ->where('uid', $this->userInfo->uid)
- ->find();
- if ($find) {
- $mer_intention_id = $find['mer_intention_id'];
- }
- if (($find['status'] != 2 && $find['status'] != 3) && $mer_intention_id > 0) {
- throw new Exception('您提交的商户入驻申请正在审核中');
- }
- // $data_other = $this->request->params([
- // 'acc_type','type','logo','desc','mer_name','mer_short_name','open_account',
- // 'bank_account','bank_location','bank_deposit','bank_branch',
- // 'name','phone','email','spread_account',
- // 'addr','lat','lng','province_id','city_id','area_id','street_id',
- // 'card_positive_person','card_back_person','idcard_no','cate_id',
- // 'district_addr','house_number','business_premises2','business_premises3',
- // 'doorhead','haike_wx_type','haike_ali_type','haike_wx_type_label',
- // 'haike_ali_type_label','identification_valid_date_start','identification_valid_date_end'
- // ]);
- $data_other = $this->request->params([
- 'acc_type','type','logo','desc','mer_name','mer_short_name','open_account',
- 'bank_account','bank_location','bank_deposit','bank_branch',
- 'name','phone','email','spread_account',
- 'addr','lat','lng','province_id','city_id','area_id','street_id',
- 'card_positive_person','card_back_person','idcard_no','cate_id',
- 'district_addr','house_number','business_premises2','business_premises3',
- 'doorhead','identification_valid_date_start','identification_valid_date_end'
- ]);
- $data_other['bank_branch']='目前不需要';
- // if (empty($data_other['branch'])){
- // $data_other['branch'] = 0;
- // } else {
- // $data_other['branch'] = 1;
- // }
- if($data_other['spread_account'] == $user['account']){
- throw new Exception('推荐人不能填写自己');
- }
- if($find['activation_code'] == ''){
- $activation_code=$this->request->params(['activation_code']);
- $expire_status=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$this->userInfo->uid)->value('status')??0;
- if(!empty($activation_code['activation_code'])||$expire_status!=0){
- if(!empty($activation_code['activation_code'])){
- $code_data=Db::name('activation_code')->where('code',$activation_code['activation_code'])->find();
- if($code_data['status']!=1){
- return app('json')->fail('此激活码已使用');
- }else{
- Db::name('activation_code')->where('code',$activation_code['activation_code'])->update(['use_uid'=>$this->userInfo->uid,'utime'=>time(),'status'=>3]);
- }
- }
- }else{
- return app('json')->fail('暂未查询到您的年费支付记录单');
- }
- }else{
- $activation_code['activation_code'] = $find['activation_code'];
- }
- if(!empty($activation_code['activation_code'])){
- $data_other['activation_code']=$activation_code['activation_code'];
- }else{
- $data_other['activation_code']=0;
- }
- $type = $data_other['type'];
- if($type == 1){ //企业
- $data = $this->request->params(['business_license','business_addr','credit_code']);
- }
- if($type == 2){//个体
- $data = $this->request->params(['business_license',
- 'business_addr','credit_code']);
- }
- if($type == 3){//个人
- //协议盖章
- $data['business_premises4'] = 'http://app.bjtdba.com/uploads/def/20210315/68f64daf38112b4a2abfb594febbc67f.jpg';
- }
- $data_arr = array_merge($data,$data_other);
- if ($this->userInfo) $data_arr['uid'] = $this->userInfo->uid;
- Db::transaction(function () use ($data_arr, $mer_intention_id,$code_id,$find) {
- // $make = app()->make(ConfigValueRepository::class);
- // $wechat = $make->more(['wechat_appid'], 0);
- // $data_arr['haike_wx_appid'] = trim($wechat['wechat_appid']);
- $merchantIntertion = app() -> make(\app\controller\admin\system\merchant\MerchantIntention::class);
- if ($mer_intention_id > 0) {
- $data_arr['status'] = 0;
- $data_arr['is_del'] = 0;
- $this->repository->update($mer_intention_id, $data_arr);
- $intention = $this->repository->get($mer_intention_id);
- } else {
- $intention = $this->repository->create($data_arr);
- //如果提交了二维码id,绑定此二维码id的用户id
- if(isset($code_id['code_id']) && $code_id['code_id'] != ''){
- Db::name("MerchantQrcode") -> where("code_id",$code_id['code_id']) -> update(['uid'=>$data_arr['uid']]);
- }
- // Db::name('log')->insert(['data'=>'开店']);
- $merchantIntertion -> switchStatus($intention->mer_intention_id);
- }
- try {
- // $sxyStatus = $this -> repository -> sxyStatus($intention->mer_intention_id);
- // if($sxyStatus['code'] == 2){
- // Db::name('log')->insert(['data'=>'去执行首信易了']);
- // $merchantIntertion->sxyApply($intention->mer_intention_id);
- // }
- if ($find['hf_status'] == 0 || $find['hf_status'] == 3){
- // Db::name('log')->insert(['data'=>'自动去执行汇付了']);
- $merchantIntertion->huihupay($intention->mer_intention_id);
- }
- } catch (\Exception $e){
- Db::name('log')->insert(['data'=>$e->getMessage()]);
- }
- // try {
- // $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
- // if (!$intention->merch_no) {
- // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => false];
- // } else {
- // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => 1,'merch_no' => $intention->merch_no];
- // }
- // $haikeApply = $haikeRepository->getWhere(['apply_id' => $intention->mer_intention_id, 'apply_type' => 1, 'status' => 3]);
- // $haikeWxApply = $haikeRepository->getWhere(['apply_id' => $intention->mer_intention_id, 'apply_type' => 2, 'status' => 3]);
- // $haikeAliApply = $haikeRepository->getWhere(['apply_id' => $intention->mer_intention_id, 'apply_type' => 3, 'status' => 3]);
- // if (!$haikeApply && $data_arr['acc_type'] == '10B') {
- // $return = $haikeRepository->createOrder($applyData);
- // if ($return['code'] != 200) {
- // Log::info('发起海科入网1:'. $return['msg']);
- // }
- // } else if ($haikeApply && !$haikeWxApply) {
- // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => 2,'merch_no' => $intention->merch_no];
- // $return = $haikeRepository->createOrder($applyData);
- // if ($return['code'] != 200) {
- // Log::info('入网后成功的商户信息修改:'. $return['msg']);
- // }
- // $return1 = $haikeRepository->haikeWxApply($applyData);
- // if ($return1['code'] != 200) {
- // Log::info('发起海科微信业务:'. $return1['msg']);
- // }
- // } else if ($haikeApply && !$haikeAliApply) {
- // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => 2,'merch_no' => $intention->merch_no];
- // $return = $haikeRepository->createOrder($applyData);
- // if ($return['code'] != 200) {
- // Log::info('入网后成功的商户信息修改:'. $return['msg']);
- // }
- // $return1 = $haikeRepository->haikeAliApply($applyData);
- // if ($return1['code'] != 200) {
- // Log::info('发起海科支付宝业务:'. $return1['msg']);
- // }
- // }
- // } catch (\Throwable $e) {
- // Log::info('发起海科入网2:'.$e -> getFile() . $e -> getLine().$e->getMessage());
- // }
- });
- } catch (\Throwable $e) {
- makeLock()->unlock();
- return app('json')->fail($e->getMessage());
- }
- makeLock()->unlock();
- return app('json')->success('提交成功');
- }
- //判断商户时候交过年费
- public function nianfei()
- {
- $expire_status=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$this->userInfo->uid)->value('status');
- // Db::name('log')->insert(['data'=>Db::name('log')->getLastSql()]);
- $code=Db::name('merchant_intention')->where('uid',$this->userInfo->uid)->value('activation_code');
- $code_status=Db::name('activation_code')->where('code',$code)->value('status');
- if($code_status==3){
- $code=true;
- }
- if($expire_status!=0||$code){
- return app('json')->success('ok');
- }else{
- return app('json')->fail('暂未查询到您的年费支付记录单');
- }
- }
- //填写的激活码能不能使用
- public function code_status()
- {
- $activation_code=$this->request->params(['activation_code']);
- $code_data=Db::name('activation_code')->where('code',$activation_code['activation_code'])->find();
- if($code_data['status']!=1){
- return app('json')->fail('此激活码不可用');
- }else{
- return app('json')->success('ok');
- }
- }
- /*判断是否有申请中的信息*/
- public function createJudge(){
- $uid = $this->userInfo->uid;
- $detail =$this->repository->intentionInfo(['uid' => $uid]);
- $code_id = $this->request->params(['code_id']);
- if(isset($code_id['code_id']) && $code_id['code_id'] != ''){
- $checkQrcode = Db::name("MerchantQrcode") -> where('code_id',$code_id['code_id']) -> find();
- if(!$checkQrcode) return app('json')->fail('二维码无效');
- $checkQrcode = Db::name("MerchantQrcode") -> where('uid',$uid) -> find();
- if($checkQrcode && $checkQrcode['code_id'] != $code_id['code_id'])return app('json')->fail('登录手机号码与二维码不匹配');
- }
- if ($detail)
- return app('json')->success($detail);
- return app('json')->fail('暂无申请信息');
- }
- /**
- * 微信支付宝经营类目
- * @return mixed
- * @author php迷途小书童
- * @created 2021/3/4 17:23
- */
- public function getBusinessCategory(){
- $data = config('businesscategory');
- return app('json')->success("获取成功",$data);
- }
- /*获取省份地址*/
- public function getProvince(){
- return app('json')->success("获取成功",$this->repository->getProvince());
- }
- /*获取城市地址*/
- public function getCity($id){
- return app('json')->success("获取成功",$this->repository->getCity($id));
- }
- /*获取区域地址*/
- public function getArea($id){
- return app('json')->success("获取成功",$this->repository->getArea($id));
- }
- /*获取街道地址*/
- public function getStreet($id){
- return app('json')->success("获取成功",$this->repository->getStreet($id));
- }
- /*扫码判断是否可收款*/
- public function checkCodeId($id){
- $find = Db::name("MerchantQrcode") -> where('code_id',$id) -> find();
- if(!$find)return app('json')->fail('二维码无效');
- $mer_id = $find['mer_id'];
- $uid = $find['uid'];
- //全新二维码,未被用户或者商户绑定
- if($mer_id == 0 && $uid == 0)return app('json')->success(['code'=>0,'msg'=>'二维码未绑定商户']);
- //已被用户绑定,商户申请中
- if($mer_id == 0) {
- $detail =$this->repository->intentionInfo(['uid' => $uid]);
- if ($detail)
- return app('json')->success($detail);
- return app('json')->fail('暂无申请信息');
- }
- //商户已审核通过返回商户id
- return app('json')->success(['code'=>1,'mer_id'=>$mer_id]);
- }
- }
|