Merchant.php
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/11/5
* Time: 15:47
*/
namespace app\home\controller;
use app\common\controller\WechatBase;
use EasyWeChat\Foundation\Application;
use think\Db;
class Merchant extends WechatBase
{
protected $user_id;
function _initialize()
{
parent::_initialize();
//判断是否授权
$user_id = get_current_user_id();
if(empty($user_id)){
$this->redirect('user/authorization_view');
}
$this->user_id = $user_id;
}
public function index(){
$data = Db::name('page')->where(['id'=>1])->find();
$this->assign('data',$data);
return $this->fetch();
}
public function enter_view(){
$domain_name = $this->request->domain();//域名
$data = Db::name('merchant_audit')->where(['user_id'=>$this->user_id])->find();
if(!empty($data)){
if($data['status'] == 1 || $data['status'] == 2){
//审核中或者审核通过提示
$this->redirect('audit_status');
}
$business_images = explode(',',$data['business_images']);
// foreach($business_images as $key => $b_i){
// $business_images[$key] = $domain_name.$b_i;
// }
$data['business_images'] = $business_images;
if(!empty($data['other_images'])){
$other_images = explode(',',$data['other_images']);
// foreach($other_images as $key => $o_i){
// $other_images[$key] = $domain_name.$o_i;
// }
$data['other_images'] = $other_images;
}
}
$this->assign('user_id',$this->user_id);
$this->assign('data',$data);
$this->assign('title','商家入驻');
$options = [
'app_id' => config('wechat.app_id'),
'secret' => config('wechat.secret'),
];
$app = new Application($options);
$js = $app->js;
$jssdk = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
$this->assign('jssdk',$jssdk);
return $this->fetch();
}
public function audit_status(){
$data = Db::name('merchant_audit')->where(['user_id'=>$this->user_id])->find();
if(empty($data)){
$this->redirect('enter_view');
}
$title = '';
if($data['status'] == 3){
$this->redirect('enter_view');
}else if($data['status'] == 2){
$title = "审核通过";
}else if($data['status'] == 1){
$title = "审核中";
}
$this->assign('title',$title);
$this->assign('data',$data);
return $this->fetch();
}
/**
* 提交申请
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function merchant_enter_submit(){
$param = $this->request->param();
$validate = new \think\Validate([
'user_id' => 'require',
'merchant_title' => 'require',
'merchant_name' => 'require',
'merchant_mobile' => 'require',
'business_images' => 'require',
]);
$validate->message([
'user_id' => 'user_id参数错误',
'merchant_title' => 'merchant_title参数错误',
'merchant_name' => 'merchant_name参数错误',
'merchant_mobile' => 'merchant_mobile参数错误',
'business_images' => 'business_images参数错误',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
if(!empty($param['other_images'])){
$param['other_images'] = implode(',',$param['other_images']);
}else{
$param['other_images'] = null;
}
$param['business_images'] = implode(',',$param['business_images']);
$data = Db::name('merchant_audit')->where(['user_id'=>$this->user_id])->find();
if(!empty($data)){
if($data['expiration_time'] > time() && $data['status'] == 3){
$this->error("请于$data[expiration_time]后再来提交");
}else if($data['status'] == 2){
$this->error("您已经是商家了");
}else if($data['status'] == 1){
$this->error('正在审核中');
}else{
$param['status'] = 1;
Db::name('merchant_audit')->where(['user_id'=>$param['user_id']])->update($param);
}
}else{
$param['createtime'] = time();
Db::name('merchant_audit')->insert($param);
}
$this->success('success');
}
}