Index.php
10.0 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
namespace app\api\controller\v1;
use addons\qrcode\library\Service;
use app\common\controller\Api;
use app\common\exception\UploadException;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\library\Upload;
use fast\Random;
use think\Cache;
use think\Config;
use think\Db;
use think\Response;
use think\Validate;
use app\server\Synthesis;
/**
* 首页公共
*/
class Index extends Api
{
protected $noNeedLogin = ["*"];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
}
/***
* 1_0、上传图片、文件到服务器
*/
public function upload()
{
if ($this->request->isPost()) {
$config = [
'size' => 2097152,
'ext' => 'jpeg,jpg,png,xls,xlsx'
];
$file = $this->request->file('file');
$upload_path = str_replace('\\', '/', ROOT_PATH . 'public/uploads');
$save_path = '/uploads/';
$info = $file->validate($config)->move($upload_path);
$domain = get_root_url();
if ($info) {
$data['filepath'] = $domain . str_replace('\\', '/', $save_path . $info->getSaveName());
$data['fileurl'] = str_replace('\\', '/', $save_path . $info->getSaveName());
$files = $file->getInfo();
$data['oldname'] = explode('.', $files['name']);
$data['oldname'] = $data['oldname'][0];
$this->success('文件上传成功', $data);
} else {
$this->error("图片上传失败");//$file->getError()
}
}
}
/**
* 1_1、重新获取管理员信息
*/
public function check_mng()
{
$post = $this->request->param();
$client_type = $post['client_type'] == 2 ? 2 : 1; //1农场端 2食堂端
$return_data = $this->auth->getUserinfo();
$is_mng_user = 0;//是否是农场管理员 0不是 1是
$mng_area = [];//管辖农场(多个)
$is_mng_user2 = 0;//是否是食堂管理员 0不是 1是
$mng_area2 = [];//管辖食堂(多个)
//检查下user表手机号,若有手机号就看下hc_area_code_mng有没有对应手机号,有的话就把id绑定上
if (!empty($return_data['mobile'])) {
$exsit_mobile = Db::name("farm_manager")->where("mng_admin_phone", $return_data['mobile'])->find();
if (!empty($exsit_mobile)) {
//更新管理员表的mng_user_id
Db::name("farm_manager")->where("mng_admin_phone", $return_data['mobile'])->update(["mng_user_id" => $return_data['id']]);
//将用户表中的基础信息更新一下
if ($exsit_mobile['mng_admin_name']) {
Db::name("user")->where("id", $return_data['id'])->update(["username" => $exsit_mobile['mng_admin_name']]);
}
}
$exsit_mobile2 = Db::name("farm_canteenmanager")->where("mng_admin_phone", $return_data['mobile'])->find();
if (!empty($exsit_mobile2)) {
//更新管理员表的mng_user_id
Db::name("farm_canteenmanager")->where("mng_admin_phone", $return_data['mobile'])->update(["mng_user_id" => $return_data['id']]);
//将用户表中的基础信息更新一下
if ($exsit_mobile2['mng_admin_name']) {
Db::name("user")->where("id", $return_data['id'])->update(["username" => $exsit_mobile2['mng_admin_name']]);
}
}
}
$area = Db::name("farm_manager")->alias("a")
->join("farm_farm b", "b.id=a.farm_farm_id")
->where("a.mng_user_id", $return_data['id'])->field("b.id as code,b.name")->select();
if (!empty($area)) {
$is_mng_user = 1;
$mng_area = $area;
if ($exsit_mobile['mng_admin_name'] && $client_type == 1) {
$return_data['username'] = $exsit_mobile['mng_admin_name'];
}
}
$return_data['is_mng_user'] = $is_mng_user;
$return_data['mng_area'] = $mng_area;
$area2 = Db::name("farm_canteenmanager")->alias("a")
->join("farm_canteen b", "b.id=a.farm_canteen_id")
->where("a.mng_user_id", $return_data['id'])->field("b.id as code,b.name")->select();
if (!empty($area2)) {
$is_mng_user2 = 1;
$mng_area2 = $area2;
if ($exsit_mobile['mng_admin_name'] && $client_type == 2) {
$return_data['username'] = $exsit_mobile['mng_admin_name'];
}
}
$return_data['is_mng_user2'] = $is_mng_user2;
$return_data['mng_area2'] = $mng_area2;
if (empty($area) && empty($area2)) {
$this->error("您还不是管理员,请在后台绑定后操作!");
}
$return_data['avatar'] = full_image($return_data['avatar']);
$sex = 1;
if ($client_type == 1) {
$sex = Db::name("farm_manager")->where("mng_user_id", $return_data['id'])->value("sex");
$sex = $sex == "2" ? 2 : 1;
} elseif ($client_type == 2) {
$sex = Db::name("farm_canteenmanager")->where("mng_user_id", $return_data['id'])->value("sex");
$sex = $sex == "2" ? 2 : 1;
}
$return_data['sex'] = $sex;
$this->success("用户信息获取成功", $return_data);
}
/**
* 1_2、更新个人资料
*/
public function update_userinfo()
{
$user_id = $this->auth->id;
$post = $this->request->param("");
$update_user_data = [];//user表数据更新
$update_mng_data = [];//mng表的数据更新
if ($post['avatar']) {
//更新图片
$update_user_data["avatar"] = $post['avatar'];
}
if ($post['username']) {
$update_user_data["username"] = $post['username'];
$update_user_data["nickname"] = $post['username'];
$update_mng_data["mng_admin_name"] = $post['username'];
}
if ($post['sex']) {
$update_mng_data['sex'] = $post['sex'] == 2 ? "2" : "1";
}
if (!empty($update_user_data)) {
Db::name("user")->where("id", $user_id)->update($update_user_data);
}
if (!empty($update_mng_data)) {
Db::name("farm_manager")->where("mng_user_id", $user_id)->update($update_mng_data);
Db::name("farm_canteenmanager")->where("mng_user_id", $user_id)->update($update_mng_data);
}
$this->success("资料更新成功");
}
/**
* 10. 各模块轮播图列表(启动页、首页顶部轮播)+填报须知
*
*/
public function getWctImg()
{
//启动图片
$list = Db::name('xcx_img')->where(['type' => "1", 'status' => 1])->order('id', 'desc')->find();
$imgs = $list['images'] ? explode(',', $list['images']) : [];
$data['start_img'] = $imgs ? full_image($imgs) : [];
//首页图片
$list2 = Db::name('xcx_img')
->where(['type' => "2", 'status' => 1])
->order('id', 'desc')
->find();
$imgs2 = $list2['images'] ? explode(',', $list2['images']) : [];
$data['index_banner_img'] = $imgs2 ? full_image($imgs2) : [];
//管理端图片
$list2 = Db::name('xcx_img')
->where(['type' => "3", 'status' => 1])
->order('id', 'desc')
->find();
$imgs2 = $list2['images'] ? explode(',', $list2['images']) : [];
$data['admin_banner_img'] = $imgs2 ? full_image($imgs2) : [];
//填报须知
$data['guidance_notes'] = Config::get("site.guidance_notes");
//电话汇总连接
$data['tel_link'] = Config::get("site.tel_link");
$data['jkb_tel_content'] = Config::get("site.jkb_tel_content");
$this->success('获取成功', $data);
}
/**
* 用户注册协议、隐私协议
*/
public function regiest_xieyi()
{
$data['regist'] = config('site.user_xieyi');
$data['yinsi'] = config('site.yinsi_xieyi');
return $this->success("", $data);
}
/*
生成二维码 $href 当前用户的 分享二维码 http格式
扫码 后 跳转 首页
app/api/v1/index?share_id=$user_id
*/
public function build($href)
{
$config = get_addon_config('qrcode');
$params = $this->request->get();
$params = array_intersect_key($params, array_flip(['text', 'size', 'padding', 'errorlevel', 'foreground', 'background', 'logo', 'logosize', 'logopath', 'label', 'labelfontsize', 'labelalignment']));
$params['text'] = $href;
$params['label'] = "";
$qrCode = \addons\qrcode\library\Service::qrcode($params);
$mimetype = $config['format'] == 'png' ? 'image/png' : 'image/svg+xml';
$response = Response::create()->header("Content-Type", $mimetype);
// 直接显示二维码
// header('Content-Type: ' . $qrCode->getContentType());
// $response->content($qrCode->writeString());
// 写入到文件
if ($config['writefile']) {
$qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
if (!is_dir($qrcodePath)) {
@mkdir($qrcodePath);
}
if (is_really_writable($qrcodePath)) {
$filePath = $qrcodePath . md5(implode('', $params)) . '.' . $config['format'];
$qrCode->writeFile($filePath);
$code_name = md5(implode('', $params)) . '.' . $config['format'];
}
$code_path="/uploads/qrcode/".$code_name;
}
return $code_path;
}
/**
* 名字加*
* @param $user_name
* @return string
*/
function substr_cut($user_name){
$strlen = mb_strlen($user_name, 'utf-8'); //获取字符长度
$firstStr = mb_substr($user_name, 0, 1, 'utf-8'); //查找字符第一个
$str=$firstStr . str_repeat('*', $strlen - 1); //拼接第一个+把字符串 "* " 重复 $strlen - 1 次:
return $str;
}
}