MerchantIntention.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-07-18
  7. *
  8. *
  9. */
  10. namespace app\controller\api\store\merchant;
  11. use app\common\repositories\merchant\apply\MerchantHaikeApplyRepository;
  12. use app\common\repositories\system\config\ConfigValueRepository;
  13. use think\App;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
  16. use think\db\Where;
  17. use think\Exception;
  18. use think\facade\Cache;
  19. use think\facade\Db;
  20. use think\facade\Log;
  21. use app\controller\admin\system\merchant\MerchantIntention as merchant;
  22. class MerchantIntention extends BaseController
  23. {
  24. protected $repository;
  25. protected $userInfo;
  26. /**
  27. * @var \Redis
  28. */
  29. protected $redis;
  30. public function __construct(App $app, repository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  35. $this->redis = Cache::store('redis')->handler();
  36. }
  37. /*申请创建*/
  38. public function create()
  39. {
  40. makeLock()->lock();
  41. try {
  42. $code_id = $this->request->params(['code_id']);
  43. if(isset($code_id['code_id']) && $code_id['code_id'] != ''){
  44. $checkQrcode = Db::name("MerchantQrcode") -> where('code_id',$code_id['code_id']) -> find();
  45. if(!$checkQrcode)throw new Exception('二维码无效');
  46. //用户id不等于0 并且用户id不等与提交的用户id。二维码无效
  47. if($checkQrcode['uid'] != 0 && $checkQrcode['uid'] != $this->userInfo->uid)throw new Exception('二维码无效');
  48. }
  49. $mer_intention_id = 0;
  50. /*判断用户是否是代理/商户身份*/
  51. $user =$this->repository->getIdentity($this->userInfo->uid);
  52. // 1,2,3,4,5
  53. if(in_array($user['identity'],[4])){
  54. throw new Exception('已是商户或者代理,不能继续申请');
  55. }
  56. $real_name = $this->repository->real($this->userInfo->uid);
  57. if($real_name == 0) {
  58. throw new Exception('请先实名认证');
  59. }
  60. $find = Db::name("merchant_intention")
  61. ->where('uid', $this->userInfo->uid)
  62. ->find();
  63. if ($find) {
  64. $mer_intention_id = $find['mer_intention_id'];
  65. }
  66. if (($find['status'] != 2 && $find['status'] != 3) && $mer_intention_id > 0) {
  67. throw new Exception('您提交的商户入驻申请正在审核中');
  68. }
  69. // $data_other = $this->request->params([
  70. // 'acc_type','type','logo','desc','mer_name','mer_short_name','open_account',
  71. // 'bank_account','bank_location','bank_deposit','bank_branch',
  72. // 'name','phone','email','spread_account',
  73. // 'addr','lat','lng','province_id','city_id','area_id','street_id',
  74. // 'card_positive_person','card_back_person','idcard_no','cate_id',
  75. // 'district_addr','house_number','business_premises2','business_premises3',
  76. // 'doorhead','haike_wx_type','haike_ali_type','haike_wx_type_label',
  77. // 'haike_ali_type_label','identification_valid_date_start','identification_valid_date_end'
  78. // ]);
  79. $data_other = $this->request->params([
  80. 'acc_type','type','logo','desc','mer_name','mer_short_name','open_account',
  81. 'bank_account','bank_location','bank_deposit','bank_branch',
  82. 'name','phone','email','spread_account',
  83. 'addr','lat','lng','province_id','city_id','area_id','street_id',
  84. 'card_positive_person','card_back_person','idcard_no','cate_id',
  85. 'district_addr','house_number','business_premises2','business_premises3',
  86. 'doorhead','identification_valid_date_start','identification_valid_date_end'
  87. ]);
  88. $data_other['bank_branch']='目前不需要';
  89. // if (empty($data_other['branch'])){
  90. // $data_other['branch'] = 0;
  91. // } else {
  92. // $data_other['branch'] = 1;
  93. // }
  94. if($data_other['spread_account'] == $user['account']){
  95. throw new Exception('推荐人不能填写自己');
  96. }
  97. if($find['activation_code'] == ''){
  98. $activation_code=$this->request->params(['activation_code']);
  99. $expire_status=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$this->userInfo->uid)->value('status')??0;
  100. if(!empty($activation_code['activation_code'])||$expire_status!=0){
  101. if(!empty($activation_code['activation_code'])){
  102. $code_data=Db::name('activation_code')->where('code',$activation_code['activation_code'])->find();
  103. if($code_data['status']!=1){
  104. return app('json')->fail('此激活码已使用');
  105. }else{
  106. Db::name('activation_code')->where('code',$activation_code['activation_code'])->update(['use_uid'=>$this->userInfo->uid,'utime'=>time(),'status'=>3]);
  107. }
  108. }
  109. }else{
  110. return app('json')->fail('暂未查询到您的年费支付记录单');
  111. }
  112. }else{
  113. $activation_code['activation_code'] = $find['activation_code'];
  114. }
  115. if(!empty($activation_code['activation_code'])){
  116. $data_other['activation_code']=$activation_code['activation_code'];
  117. }else{
  118. $data_other['activation_code']=0;
  119. }
  120. $type = $data_other['type'];
  121. if($type == 1){ //企业
  122. $data = $this->request->params(['business_license','business_addr','credit_code']);
  123. }
  124. if($type == 2){//个体
  125. $data = $this->request->params(['business_license',
  126. 'business_addr','credit_code']);
  127. }
  128. if($type == 3){//个人
  129. //协议盖章
  130. $data['business_premises4'] = 'http://app.bjtdba.com/uploads/def/20210315/68f64daf38112b4a2abfb594febbc67f.jpg';
  131. }
  132. $data_arr = array_merge($data,$data_other);
  133. if ($this->userInfo) $data_arr['uid'] = $this->userInfo->uid;
  134. Db::transaction(function () use ($data_arr, $mer_intention_id,$code_id,$find) {
  135. // $make = app()->make(ConfigValueRepository::class);
  136. // $wechat = $make->more(['wechat_appid'], 0);
  137. // $data_arr['haike_wx_appid'] = trim($wechat['wechat_appid']);
  138. $merchantIntertion = app() -> make(\app\controller\admin\system\merchant\MerchantIntention::class);
  139. if ($mer_intention_id > 0) {
  140. $data_arr['status'] = 0;
  141. $data_arr['is_del'] = 0;
  142. $this->repository->update($mer_intention_id, $data_arr);
  143. $intention = $this->repository->get($mer_intention_id);
  144. } else {
  145. $intention = $this->repository->create($data_arr);
  146. //如果提交了二维码id,绑定此二维码id的用户id
  147. if(isset($code_id['code_id']) && $code_id['code_id'] != ''){
  148. Db::name("MerchantQrcode") -> where("code_id",$code_id['code_id']) -> update(['uid'=>$data_arr['uid']]);
  149. }
  150. // Db::name('log')->insert(['data'=>'开店']);
  151. $merchantIntertion -> switchStatus($intention->mer_intention_id);
  152. }
  153. try {
  154. // $sxyStatus = $this -> repository -> sxyStatus($intention->mer_intention_id);
  155. // if($sxyStatus['code'] == 2){
  156. // Db::name('log')->insert(['data'=>'去执行首信易了']);
  157. // $merchantIntertion->sxyApply($intention->mer_intention_id);
  158. // }
  159. if ($find['hf_status'] == 0 || $find['hf_status'] == 3){
  160. // Db::name('log')->insert(['data'=>'自动去执行汇付了']);
  161. $merchantIntertion->huihupay($intention->mer_intention_id);
  162. }
  163. } catch (\Exception $e){
  164. Db::name('log')->insert(['data'=>$e->getMessage()]);
  165. }
  166. // try {
  167. // $haikeRepository = app()->make(MerchantHaikeApplyRepository::class);
  168. // if (!$intention->merch_no) {
  169. // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => false];
  170. // } else {
  171. // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => 1,'merch_no' => $intention->merch_no];
  172. // }
  173. // $haikeApply = $haikeRepository->getWhere(['apply_id' => $intention->mer_intention_id, 'apply_type' => 1, 'status' => 3]);
  174. // $haikeWxApply = $haikeRepository->getWhere(['apply_id' => $intention->mer_intention_id, 'apply_type' => 2, 'status' => 3]);
  175. // $haikeAliApply = $haikeRepository->getWhere(['apply_id' => $intention->mer_intention_id, 'apply_type' => 3, 'status' => 3]);
  176. // if (!$haikeApply && $data_arr['acc_type'] == '10B') {
  177. // $return = $haikeRepository->createOrder($applyData);
  178. // if ($return['code'] != 200) {
  179. // Log::info('发起海科入网1:'. $return['msg']);
  180. // }
  181. // } else if ($haikeApply && !$haikeWxApply) {
  182. // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => 2,'merch_no' => $intention->merch_no];
  183. // $return = $haikeRepository->createOrder($applyData);
  184. // if ($return['code'] != 200) {
  185. // Log::info('入网后成功的商户信息修改:'. $return['msg']);
  186. // }
  187. // $return1 = $haikeRepository->haikeWxApply($applyData);
  188. // if ($return1['code'] != 200) {
  189. // Log::info('发起海科微信业务:'. $return1['msg']);
  190. // }
  191. // } else if ($haikeApply && !$haikeAliApply) {
  192. // $applyData = ['mer_intention_id' => $intention->mer_intention_id,'is_again' => 2,'merch_no' => $intention->merch_no];
  193. // $return = $haikeRepository->createOrder($applyData);
  194. // if ($return['code'] != 200) {
  195. // Log::info('入网后成功的商户信息修改:'. $return['msg']);
  196. // }
  197. // $return1 = $haikeRepository->haikeAliApply($applyData);
  198. // if ($return1['code'] != 200) {
  199. // Log::info('发起海科支付宝业务:'. $return1['msg']);
  200. // }
  201. // }
  202. // } catch (\Throwable $e) {
  203. // Log::info('发起海科入网2:'.$e -> getFile() . $e -> getLine().$e->getMessage());
  204. // }
  205. });
  206. } catch (\Throwable $e) {
  207. makeLock()->unlock();
  208. return app('json')->fail($e->getMessage());
  209. }
  210. makeLock()->unlock();
  211. return app('json')->success('提交成功');
  212. }
  213. //判断商户时候交过年费
  214. public function nianfei()
  215. {
  216. $expire_status=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$this->userInfo->uid)->value('status');
  217. // Db::name('log')->insert(['data'=>Db::name('log')->getLastSql()]);
  218. $code=Db::name('merchant_intention')->where('uid',$this->userInfo->uid)->value('activation_code');
  219. $code_status=Db::name('activation_code')->where('code',$code)->value('status');
  220. if($code_status==3){
  221. $code=true;
  222. }
  223. if($expire_status!=0||$code){
  224. return app('json')->success('ok');
  225. }else{
  226. return app('json')->fail('暂未查询到您的年费支付记录单');
  227. }
  228. }
  229. //填写的激活码能不能使用
  230. public function code_status()
  231. {
  232. $activation_code=$this->request->params(['activation_code']);
  233. $code_data=Db::name('activation_code')->where('code',$activation_code['activation_code'])->find();
  234. if($code_data['status']!=1){
  235. return app('json')->fail('此激活码不可用');
  236. }else{
  237. return app('json')->success('ok');
  238. }
  239. }
  240. /*判断是否有申请中的信息*/
  241. public function createJudge(){
  242. $uid = $this->userInfo->uid;
  243. $detail =$this->repository->intentionInfo(['uid' => $uid]);
  244. $code_id = $this->request->params(['code_id']);
  245. if(isset($code_id['code_id']) && $code_id['code_id'] != ''){
  246. $checkQrcode = Db::name("MerchantQrcode") -> where('code_id',$code_id['code_id']) -> find();
  247. if(!$checkQrcode) return app('json')->fail('二维码无效');
  248. $checkQrcode = Db::name("MerchantQrcode") -> where('uid',$uid) -> find();
  249. if($checkQrcode && $checkQrcode['code_id'] != $code_id['code_id'])return app('json')->fail('登录手机号码与二维码不匹配');
  250. }
  251. if ($detail)
  252. return app('json')->success($detail);
  253. return app('json')->fail('暂无申请信息');
  254. }
  255. /**
  256. * 微信支付宝经营类目
  257. * @return mixed
  258. * @author php迷途小书童
  259. * @created 2021/3/4 17:23
  260. */
  261. public function getBusinessCategory(){
  262. $data = config('businesscategory');
  263. return app('json')->success("获取成功",$data);
  264. }
  265. /*获取省份地址*/
  266. public function getProvince(){
  267. return app('json')->success("获取成功",$this->repository->getProvince());
  268. }
  269. /*获取城市地址*/
  270. public function getCity($id){
  271. return app('json')->success("获取成功",$this->repository->getCity($id));
  272. }
  273. /*获取区域地址*/
  274. public function getArea($id){
  275. return app('json')->success("获取成功",$this->repository->getArea($id));
  276. }
  277. /*获取街道地址*/
  278. public function getStreet($id){
  279. return app('json')->success("获取成功",$this->repository->getStreet($id));
  280. }
  281. /*扫码判断是否可收款*/
  282. public function checkCodeId($id){
  283. $find = Db::name("MerchantQrcode") -> where('code_id',$id) -> find();
  284. if(!$find)return app('json')->fail('二维码无效');
  285. $mer_id = $find['mer_id'];
  286. $uid = $find['uid'];
  287. //全新二维码,未被用户或者商户绑定
  288. if($mer_id == 0 && $uid == 0)return app('json')->success(['code'=>0,'msg'=>'二维码未绑定商户']);
  289. //已被用户绑定,商户申请中
  290. if($mer_id == 0) {
  291. $detail =$this->repository->intentionInfo(['uid' => $uid]);
  292. if ($detail)
  293. return app('json')->success($detail);
  294. return app('json')->fail('暂无申请信息');
  295. }
  296. //商户已审核通过返回商户id
  297. return app('json')->success(['code'=>1,'mer_id'=>$mer_id]);
  298. }
  299. }