正在显示
32 个修改的文件
包含
4832 行增加
和
0 行删除
addons/wechat/.addonrc
0 → 100644
1 | +{"files":["application\\admin\\controller\\wechat\\Autoreply.php","application\\admin\\controller\\wechat\\Config.php","application\\admin\\controller\\wechat\\Menu.php","application\\admin\\controller\\wechat\\Response.php","application\\admin\\lang\\zh-cn\\wechat\\autoreply.php","application\\admin\\lang\\zh-cn\\wechat\\config.php","application\\admin\\lang\\zh-cn\\wechat\\response.php","application\\admin\\model\\WechatAutoreply.php","application\\admin\\model\\WechatCaptcha.php","application\\admin\\model\\WechatConfig.php","application\\admin\\model\\WechatContext.php","application\\admin\\model\\WechatResponse.php","application\\admin\\view\\wechat\\autoreply\\add.html","application\\admin\\view\\wechat\\autoreply\\edit.html","application\\admin\\view\\wechat\\autoreply\\index.html","application\\admin\\view\\wechat\\config\\add.html","application\\admin\\view\\wechat\\config\\edit.html","application\\admin\\view\\wechat\\config\\index.html","application\\admin\\view\\wechat\\menu\\index.html","application\\admin\\view\\wechat\\response\\add.html","application\\admin\\view\\wechat\\response\\edit.html","application\\admin\\view\\wechat\\response\\index.html","application\\admin\\view\\wechat\\response\\select.html","public\\assets\\js\\backend\\wechat\\autoreply.js","public\\assets\\js\\backend\\wechat\\config.js","public\\assets\\js\\backend\\wechat\\menu.js","public\\assets\\js\\backend\\wechat\\response.js","public\\assets\\addons\\wechat\\css\\menu.css","public\\assets\\addons\\wechat\\images\\mobile_footer_bg.png","public\\assets\\addons\\wechat\\images\\mobile_header_bg.png","public\\assets\\addons\\wechat\\images\\mobile_index.png","public\\assets\\addons\\wechat\\images\\weixin_icon.png"],"license":"regular","licenseto":"56052","licensekey":"z43Dir5MYRb7LdKm 5dY2yLiHBuRzRCkDrrhR3w==","domains":[],"licensecodes":[],"validations":[],"menus":["wechat","wechat\/autoreply","wechat\/autoreply\/index","wechat\/autoreply\/add","wechat\/autoreply\/edit","wechat\/autoreply\/del","wechat\/autoreply\/multi","wechat\/config","wechat\/config\/index","wechat\/config\/add","wechat\/config\/edit","wechat\/config\/del","wechat\/config\/multi","wechat\/menu","wechat\/menu\/index","wechat\/menu\/add","wechat\/menu\/edit","wechat\/menu\/del","wechat\/menu\/remote","wechat\/menu\/sync","wechat\/menu\/multi","wechat\/response","wechat\/response\/index","wechat\/response\/add","wechat\/response\/edit","wechat\/response\/del","wechat\/response\/select","wechat\/response\/multi"]} |
addons/wechat/Wechat.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat; | ||
4 | + | ||
5 | +use app\common\library\Menu; | ||
6 | +use think\Addons; | ||
7 | + | ||
8 | +/** | ||
9 | + * 微信插件 | ||
10 | + */ | ||
11 | +class Wechat extends Addons | ||
12 | +{ | ||
13 | + | ||
14 | + /** | ||
15 | + * 插件安装方法 | ||
16 | + * @return bool | ||
17 | + */ | ||
18 | + public function install() | ||
19 | + { | ||
20 | + $menu = [ | ||
21 | + [ | ||
22 | + 'name' => 'wechat', | ||
23 | + 'title' => '微信管理', | ||
24 | + 'icon' => 'fa fa-wechat', | ||
25 | + 'sublist' => [ | ||
26 | + [ | ||
27 | + 'name' => 'wechat/autoreply', | ||
28 | + 'title' => '自动回复管理', | ||
29 | + 'icon' => 'fa fa-reply-all', | ||
30 | + 'sublist' => [ | ||
31 | + ['name' => 'wechat/autoreply/index', 'title' => '查看'], | ||
32 | + ['name' => 'wechat/autoreply/add', 'title' => '添加'], | ||
33 | + ['name' => 'wechat/autoreply/edit', 'title' => '修改'], | ||
34 | + ['name' => 'wechat/autoreply/del', 'title' => '删除'], | ||
35 | + ['name' => 'wechat/autoreply/multi', 'title' => '批量更新'], | ||
36 | + ] | ||
37 | + ], | ||
38 | + [ | ||
39 | + 'name' => 'wechat/config', | ||
40 | + 'title' => '配置管理', | ||
41 | + 'icon' => 'fa fa-cog', | ||
42 | + 'sublist' => [ | ||
43 | + ['name' => 'wechat/config/index', 'title' => '查看'], | ||
44 | + ['name' => 'wechat/config/add', 'title' => '添加'], | ||
45 | + ['name' => 'wechat/config/edit', 'title' => '修改'], | ||
46 | + ['name' => 'wechat/config/del', 'title' => '删除'], | ||
47 | + ['name' => 'wechat/config/multi', 'title' => '批量更新'], | ||
48 | + ] | ||
49 | + ], | ||
50 | + [ | ||
51 | + 'name' => 'wechat/menu', | ||
52 | + 'title' => '菜单管理', | ||
53 | + 'icon' => 'fa fa-list', | ||
54 | + 'sublist' => [ | ||
55 | + ['name' => 'wechat/menu/index', 'title' => '查看'], | ||
56 | + ['name' => 'wechat/menu/add', 'title' => '添加'], | ||
57 | + ['name' => 'wechat/menu/edit', 'title' => '修改'], | ||
58 | + ['name' => 'wechat/menu/del', 'title' => '删除'], | ||
59 | + ['name' => 'wechat/menu/remote', 'title' => '加载远程菜单'], | ||
60 | + ['name' => 'wechat/menu/sync', 'title' => '同步'], | ||
61 | + ['name' => 'wechat/menu/multi', 'title' => '批量更新'], | ||
62 | + ] | ||
63 | + ], | ||
64 | + [ | ||
65 | + 'name' => 'wechat/response', | ||
66 | + 'title' => '资源管理', | ||
67 | + 'icon' => 'fa fa-list-alt', | ||
68 | + 'sublist' => [ | ||
69 | + ['name' => 'wechat/response/index', 'title' => '查看'], | ||
70 | + ['name' => 'wechat/response/add', 'title' => '添加'], | ||
71 | + ['name' => 'wechat/response/edit', 'title' => '修改'], | ||
72 | + ['name' => 'wechat/response/del', 'title' => '删除'], | ||
73 | + ['name' => 'wechat/response/select', 'title' => '选择'], | ||
74 | + ['name' => 'wechat/response/multi', 'title' => '批量更新'], | ||
75 | + ] | ||
76 | + ] | ||
77 | + ] | ||
78 | + ] | ||
79 | + ]; | ||
80 | + Menu::create($menu); | ||
81 | + return true; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * 插件卸载方法 | ||
86 | + * @return bool | ||
87 | + */ | ||
88 | + public function uninstall() | ||
89 | + { | ||
90 | + Menu::delete('wechat'); | ||
91 | + return true; | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * 插件启用方法 | ||
96 | + */ | ||
97 | + public function enable() | ||
98 | + { | ||
99 | + Menu::enable('wechat'); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * 插件禁用方法 | ||
104 | + */ | ||
105 | + public function disable() | ||
106 | + { | ||
107 | + Menu::disable('wechat'); | ||
108 | + } | ||
109 | + | ||
110 | +} |
addons/wechat/config.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +return [ | ||
4 | + [ | ||
5 | + 'name' => 'app_id', | ||
6 | + 'title' => 'app_id', | ||
7 | + 'type' => 'string', | ||
8 | + 'content' => [], | ||
9 | + 'value' => 'wxb7dd0c03865a94e0', | ||
10 | + 'rule' => 'required', | ||
11 | + 'msg' => '', | ||
12 | + 'tip' => '', | ||
13 | + 'ok' => '', | ||
14 | + 'extend' => '', | ||
15 | + ], | ||
16 | + [ | ||
17 | + 'name' => 'secret', | ||
18 | + 'title' => 'secret', | ||
19 | + 'type' => 'string', | ||
20 | + 'content' => [], | ||
21 | + 'value' => '6af75a6fb8211da45631630e34769f82', | ||
22 | + 'rule' => 'required', | ||
23 | + 'msg' => '', | ||
24 | + 'tip' => '', | ||
25 | + 'ok' => '', | ||
26 | + 'extend' => '', | ||
27 | + ], | ||
28 | + [ | ||
29 | + 'name' => 'token', | ||
30 | + 'title' => 'token', | ||
31 | + 'type' => 'string', | ||
32 | + 'content' => [], | ||
33 | + 'value' => 'Fdc2022666fdC', | ||
34 | + 'rule' => 'required', | ||
35 | + 'msg' => '', | ||
36 | + 'tip' => '', | ||
37 | + 'ok' => '', | ||
38 | + 'extend' => '', | ||
39 | + ], | ||
40 | + [ | ||
41 | + 'name' => 'aes_key', | ||
42 | + 'title' => 'aes_key', | ||
43 | + 'type' => 'string', | ||
44 | + 'content' => [], | ||
45 | + 'value' => 'vfVRWaOmV7B19NqjE6zPBHaBTEDgv71plzhEGr8SxiQ', | ||
46 | + 'rule' => 'required', | ||
47 | + 'msg' => '', | ||
48 | + 'tip' => '', | ||
49 | + 'ok' => '', | ||
50 | + 'extend' => '', | ||
51 | + ], | ||
52 | + [ | ||
53 | + 'name' => 'debug', | ||
54 | + 'title' => '调试模式', | ||
55 | + 'type' => 'radio', | ||
56 | + 'content' => [ | ||
57 | + '否', | ||
58 | + '是', | ||
59 | + ], | ||
60 | + 'value' => '1', | ||
61 | + 'rule' => 'required', | ||
62 | + 'msg' => '', | ||
63 | + 'tip' => '', | ||
64 | + 'ok' => '', | ||
65 | + 'extend' => '', | ||
66 | + ], | ||
67 | + [ | ||
68 | + 'name' => 'log_level', | ||
69 | + 'title' => '日志记录等级', | ||
70 | + 'type' => 'select', | ||
71 | + 'content' => [ | ||
72 | + 'debug' => 'debug', | ||
73 | + 'info' => 'info', | ||
74 | + 'notice' => 'notice', | ||
75 | + 'warning' => 'warning', | ||
76 | + 'error' => 'error', | ||
77 | + 'critical' => 'critical', | ||
78 | + 'alert' => 'alert', | ||
79 | + 'emergency' => 'emergency', | ||
80 | + ], | ||
81 | + 'value' => 'info', | ||
82 | + 'rule' => 'required', | ||
83 | + 'msg' => '', | ||
84 | + 'tip' => '生产环境日志记录等级', | ||
85 | + 'ok' => '', | ||
86 | + 'extend' => '', | ||
87 | + ], | ||
88 | + [ | ||
89 | + 'name' => 'oauth_callback', | ||
90 | + 'title' => '登录回调', | ||
91 | + 'type' => 'string', | ||
92 | + 'content' => [], | ||
93 | + 'value' => 'https://fdc.xp.yn.cn/', | ||
94 | + 'rule' => 'required', | ||
95 | + 'msg' => '', | ||
96 | + 'tip' => '', | ||
97 | + 'ok' => '', | ||
98 | + 'extend' => '', | ||
99 | + ], | ||
100 | +]; |
addons/wechat/controller/Captcha.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat\controller; | ||
4 | + | ||
5 | +use addons\wechat\library\Wechat; | ||
6 | +use addons\wechat\model\WechatCaptcha; | ||
7 | +use fast\Http; | ||
8 | + | ||
9 | +/** | ||
10 | + * 微信验证码验证接口 | ||
11 | + */ | ||
12 | +class Captcha extends \think\addons\Controller | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * 验证码检测接口 | ||
17 | + */ | ||
18 | + public function check() | ||
19 | + { | ||
20 | + $captcha = $this->request->post("captcha"); | ||
21 | + $event = $this->request->post("event"); | ||
22 | + $result = WechatCaptcha::check($captcha, $event); | ||
23 | + if ($result) { | ||
24 | + $this->success("验证码正确"); | ||
25 | + } else { | ||
26 | + $this->error("验证码错误"); | ||
27 | + } | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * 验证码发送接口 | ||
32 | + */ | ||
33 | + public function send() | ||
34 | + { | ||
35 | + $ip = $this->request->ip(); | ||
36 | + $event = $this->request->post("event"); | ||
37 | + if (!$event) { | ||
38 | + $this->error("参数错误"); | ||
39 | + } | ||
40 | + $captch = WechatCaptcha::where('ip', $ip) | ||
41 | + ->where('event', $event) | ||
42 | + ->whereTime('createtime', '-2 minutes') | ||
43 | + ->find(); | ||
44 | + if ($captch) { | ||
45 | + $this->error("获取频繁,请稍后重试"); | ||
46 | + } | ||
47 | + $token = Wechat::getAccessToken(); | ||
48 | + if (!$token) { | ||
49 | + $this->error("发送失败,请稍后重试"); | ||
50 | + } | ||
51 | + $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$token}"; | ||
52 | + $params = [ | ||
53 | + 'expire_seconds' => 120, | ||
54 | + 'action_name' => 'QR_STR_SCENE', | ||
55 | + 'action_info' => [ | ||
56 | + 'scene' => [ | ||
57 | + 'scene_str' => "captcha_" . $event . "_" . $ip, | ||
58 | + ] | ||
59 | + ], | ||
60 | + ]; | ||
61 | + //获取验证码 | ||
62 | + $result = Http::sendRequest($url, json_encode($params)); | ||
63 | + if ($result['ret']) { | ||
64 | + $msg = (array)json_decode($result['msg'], true); | ||
65 | + if (isset($msg['ticket']) && isset($msg['url'])) { | ||
66 | + $this->success("", null, ['image' => "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($msg['ticket']), 'url' => $msg['url']]); | ||
67 | + } | ||
68 | + } | ||
69 | + $this->error("获取失败!请稍后重试"); | ||
70 | + } | ||
71 | + | ||
72 | +} |
addons/wechat/controller/Index.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat\controller; | ||
4 | + | ||
5 | +use addons\wechat\library\Config; | ||
6 | +use addons\wechat\model\WechatAutoreply; | ||
7 | +use addons\wechat\model\WechatCaptcha; | ||
8 | +use addons\wechat\model\WechatContext; | ||
9 | +use addons\wechat\model\WechatResponse; | ||
10 | +use addons\wechat\model\WechatConfig; | ||
11 | + | ||
12 | +use app\common\library\Menu; | ||
13 | +use EasyWeChat\Factory; | ||
14 | +use addons\wechat\library\Wechat as WechatService; | ||
15 | +use addons\wechat\library\Config as ConfigService; | ||
16 | +use think\Log; | ||
17 | +use think\Db; | ||
18 | +use fast\Date; | ||
19 | +use fast\Random; | ||
20 | +use fast\Http; | ||
21 | +use addons\third\model\Third; | ||
22 | +use think\Session; | ||
23 | + | ||
24 | +/** | ||
25 | + * 微信接口 | ||
26 | + */ | ||
27 | +class Index extends \think\addons\Controller | ||
28 | +{ | ||
29 | + | ||
30 | + public $app = null; | ||
31 | + | ||
32 | + public function _initialize() | ||
33 | + { | ||
34 | + parent::_initialize(); | ||
35 | + $this->app = Factory::officialAccount(Config::load()); | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * | ||
40 | + */ | ||
41 | + public function index() | ||
42 | + { | ||
43 | + | ||
44 | + $menu = [ | ||
45 | + [ | ||
46 | + 'name' => 'wechat', | ||
47 | + 'title' => '微信管理', | ||
48 | + 'icon' => 'fa fa-wechat', | ||
49 | + 'sublist' => [ | ||
50 | + [ | ||
51 | + 'name' => 'wechat/autoreply', | ||
52 | + 'title' => '自动回复管理', | ||
53 | + 'icon' => 'fa fa-reply-all', | ||
54 | + 'sublist' => [ | ||
55 | + ['name' => 'wechat/autoreply/index', 'title' => '查看'], | ||
56 | + ['name' => 'wechat/autoreply/add', 'title' => '添加'], | ||
57 | + ['name' => 'wechat/autoreply/edit', 'title' => '修改'], | ||
58 | + ['name' => 'wechat/autoreply/del', 'title' => '删除'], | ||
59 | + ['name' => 'wechat/autoreply/multi', 'title' => '批量更新'], | ||
60 | + ] | ||
61 | + ], | ||
62 | + [ | ||
63 | + 'name' => 'wechat/config', | ||
64 | + 'title' => '配置管理', | ||
65 | + 'icon' => 'fa fa-cog', | ||
66 | + 'sublist' => [ | ||
67 | + ['name' => 'wechat/config/index', 'title' => '查看'], | ||
68 | + ['name' => 'wechat/config/add', 'title' => '添加'], | ||
69 | + ['name' => 'wechat/config/edit', 'title' => '修改'], | ||
70 | + ['name' => 'wechat/config/del', 'title' => '删除'], | ||
71 | + ['name' => 'wechat/config/multi', 'title' => '批量更新'], | ||
72 | + ] | ||
73 | + ], | ||
74 | + [ | ||
75 | + 'name' => 'wechat/menu', | ||
76 | + 'title' => '菜单管理', | ||
77 | + 'icon' => 'fa fa-list', | ||
78 | + 'sublist' => [ | ||
79 | + ['name' => 'wechat/menu/index', 'title' => '查看'], | ||
80 | + ['name' => 'wechat/menu/add', 'title' => '添加'], | ||
81 | + ['name' => 'wechat/menu/edit', 'title' => '修改'], | ||
82 | + ['name' => 'wechat/menu/del', 'title' => '删除'], | ||
83 | + ['name' => 'wechat/menu/remote', 'title' => '加载远程菜单'], | ||
84 | + ['name' => 'wechat/menu/sync', 'title' => '同步'], | ||
85 | + ['name' => 'wechat/menu/multi', 'title' => '批量更新'], | ||
86 | + ] | ||
87 | + ], | ||
88 | + [ | ||
89 | + 'name' => 'wechat/response', | ||
90 | + 'title' => '资源管理', | ||
91 | + 'icon' => 'fa fa-list-alt', | ||
92 | + 'sublist' => [ | ||
93 | + ['name' => 'wechat/response/index', 'title' => '查看'], | ||
94 | + ['name' => 'wechat/response/add', 'title' => '添加'], | ||
95 | + ['name' => 'wechat/response/edit', 'title' => '修改'], | ||
96 | + ['name' => 'wechat/response/del', 'title' => '删除'], | ||
97 | + ['name' => 'wechat/response/select', 'title' => '选择'], | ||
98 | + ['name' => 'wechat/response/multi', 'title' => '批量更新'], | ||
99 | + ] | ||
100 | + ] | ||
101 | + ] | ||
102 | + ] | ||
103 | + ]; | ||
104 | + Menu::create($menu); | ||
105 | + return true; | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * 微信API对接接口 | ||
110 | + */ | ||
111 | + public function api() | ||
112 | + { | ||
113 | + $this->app->server->push(function ($message) { | ||
114 | + $wechatService = new WechatService; | ||
115 | + | ||
116 | + $matches = null; | ||
117 | + $openid = $message['FromUserName']; | ||
118 | + $to_openid = $message['ToUserName']; | ||
119 | + //file_put_contents("pcl_wct.log", date("Y-m-d H:i:s") . "1-::" . json_encode($message, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
120 | + | ||
121 | + $unknownMessage = WechatConfig::getValue('default.unknown.message'); | ||
122 | + $unknownMessage = $unknownMessage ? $unknownMessage : ""; | ||
123 | + | ||
124 | + switch ($message['MsgType']) { | ||
125 | + case 'event': //事件消息 | ||
126 | + $event = $message['Event']; | ||
127 | + $eventkey = $message['EventKey'] ? $message['EventKey'] : $message['Event']; | ||
128 | + //验证码消息 | ||
129 | + if (in_array($event, ['subscribe', 'SCAN']) && preg_match("/^captcha_([a-zA-Z0-9]+)_([0-9\.]+)/", $eventkey, $matches)) { | ||
130 | + return WechatCaptcha::send($openid, $matches[1], $matches[2]); | ||
131 | + } | ||
132 | + switch ($event) { | ||
133 | + case 'subscribe'://添加关注 | ||
134 | + $subscribeMessage = WechatConfig::getValue('default.subscribe.message'); | ||
135 | + //$subscribeMessage = $subscribeMessage ? $subscribeMessage : "欢迎关注惠蒙房地产交易综合服务大厅!"; | ||
136 | + $subscribeMessage = '欢迎关注蒙自市房地产交易综合服务大厅,<a data-miniprogram-appid="wx0a5edd82c146e6f4" data-miniprogram-path="pages/home/mine1/mine1" href="https://fdc.xp.yn.cn" data-miniprogram-type="text">点击链接注册成为物业经理</a>'; | ||
137 | + //获得access_token | ||
138 | + $getAccessToken = $this->getAccessToken(); | ||
139 | + //获得用户信息 | ||
140 | + $params = []; | ||
141 | + $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $getAccessToken . "&openid=" . $openid . "&lang=zh_CN"; | ||
142 | + $userInfo = Http::sendRequest($url, $params, 'GET'); | ||
143 | + //根据UnionID判断用户是否已注册 | ||
144 | + | ||
145 | + $u_info_data = json_decode($userInfo['msg'], true); | ||
146 | + | ||
147 | + $ucks = Db::name('wct_user') | ||
148 | + ->where(['unionid' => $u_info_data['unionid']]) | ||
149 | + ->find(); | ||
150 | + | ||
151 | + if (empty($ucks)) { | ||
152 | + $useradd['unionid'] = $u_info_data['unionid']; | ||
153 | + $useradd['wx_openid'] = $openid; | ||
154 | + $useradd['loginip'] = request()->ip(); | ||
155 | + $useradd['createtime'] = time(); | ||
156 | + Db::name('wct_user')->insertGetId($useradd); | ||
157 | + } | ||
158 | + | ||
159 | + file_put_contents("pcl_wct.log", date("Y-m-d H:i:s") . "::3-" . json_encode($userInfo['msg'], JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
160 | + return $subscribeMessage; | ||
161 | + | ||
162 | + case 'unsubscribe'://取消关注 | ||
163 | + return ''; | ||
164 | + case 'LOCATION'://获取地理位置 | ||
165 | + return ''; | ||
166 | + case 'VIEW': //跳转链接,eventkey为链接 | ||
167 | + return ''; | ||
168 | + case 'SCAN': //扫码 | ||
169 | + return ''; | ||
170 | + default: | ||
171 | + break; | ||
172 | + } | ||
173 | + | ||
174 | + $wechatResponse = WechatResponse::where(["eventkey" => $eventkey, 'status' => 'normal'])->find(); | ||
175 | + if ($wechatResponse) { | ||
176 | + $responseContent = (array)json_decode($wechatResponse['content'], true); | ||
177 | + $wechatContext = WechatContext::where(['openid' => $openid])->order('id', 'desc')->find(); | ||
178 | + $data = ['eventkey' => $eventkey, 'command' => '', 'refreshtime' => time(), 'openid' => $openid]; | ||
179 | + if ($wechatContext) { | ||
180 | + $wechatContext->save($data); | ||
181 | + } else { | ||
182 | + $wechatContext = WechatContext::create($data, true); | ||
183 | + } | ||
184 | + $result = $wechatService->response($this, $openid, '', $responseContent, $wechatContext); | ||
185 | + if ($result) { | ||
186 | + return $result; | ||
187 | + } | ||
188 | + } | ||
189 | + return $unknownMessage; | ||
190 | + case 'text': //文字消息 | ||
191 | + case 'image': //图片消息 | ||
192 | + case 'voice': //语音消息 | ||
193 | + case 'video': //视频消息 | ||
194 | + case 'location': //坐标消息 | ||
195 | + case 'link': //链接消息 | ||
196 | + default: //其它消息 | ||
197 | + | ||
198 | + //自动回复处理 | ||
199 | + if ($message['MsgType'] == 'text') { | ||
200 | + $autoreply = null; | ||
201 | + $autoreplyList = WechatAutoreply::where('status', 'normal')->cache(true)->order('weigh DESC,id DESC')->select(); | ||
202 | + foreach ($autoreplyList as $index => $item) { | ||
203 | + //完全匹配和正则匹配 | ||
204 | + if ($item['text'] == $message['Content'] || (in_array(mb_substr($item['text'], 0, 1), ['#', '~', '/']) && preg_match($item['text'], $message['Content'], $matches))) { | ||
205 | + $autoreply = $item; | ||
206 | + break; | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
210 | + if ($autoreply) { | ||
211 | + $wechatResponse = WechatResponse::where(["eventkey" => $autoreply['eventkey'], 'status' => 'normal'])->find(); | ||
212 | + if ($wechatResponse) { | ||
213 | + $responseContent = (array)json_decode($wechatResponse['content'], true); | ||
214 | + $wechatContext = WechatContext::where(['openid' => $openid])->order('id', 'desc')->find(); | ||
215 | + $result = $wechatService->response($this, $openid, $message['Content'], $responseContent, $wechatContext, $matches); | ||
216 | + if ($result) { | ||
217 | + return $result; | ||
218 | + } | ||
219 | + } | ||
220 | + } | ||
221 | + } | ||
222 | + return $unknownMessage; | ||
223 | + } | ||
224 | + return ""; //SUCCESS | ||
225 | + }); | ||
226 | + | ||
227 | + $response = $this->app->server->serve(); | ||
228 | + //file_put_contents("pcl_wct.log", date("Y-m-d H:i:s") . "::4-" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
229 | + // 将响应输出 | ||
230 | + $response->send(); | ||
231 | + return; | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * 登录回调 | ||
236 | + */ | ||
237 | + public function callback() | ||
238 | + { | ||
239 | + | ||
240 | + | ||
241 | + } | ||
242 | + | ||
243 | + /** | ||
244 | + * 支付回调 | ||
245 | + */ | ||
246 | + public function notify() | ||
247 | + { | ||
248 | + Log::record(file_get_contents('php://input'), "notify"); | ||
249 | + $response = $this->app->handlePaidNotify(function ($message, $fail) { | ||
250 | + // 你的逻辑 | ||
251 | + return true; | ||
252 | + // 或者错误消息 | ||
253 | + $fail('Order not exists.'); | ||
254 | + }); | ||
255 | + | ||
256 | + $response->send(); | ||
257 | + return; | ||
258 | + } | ||
259 | + | ||
260 | + /** | ||
261 | + * 获取Token | ||
262 | + */ | ||
263 | + public static function getAccessToken() | ||
264 | + { | ||
265 | + $token = Session::get('wechat_access_token'); | ||
266 | + if (!$token) { | ||
267 | + $config = get_addon_config('wechat'); | ||
268 | + $params = [ | ||
269 | + 'grant_type' => 'client_credential', | ||
270 | + 'appid' => $config['app_id'], | ||
271 | + 'secret' => $config['secret'], | ||
272 | + ]; | ||
273 | + $url = "https://api.weixin.qq.com/cgi-bin/token"; | ||
274 | + $result = Http::sendRequest($url, $params, 'GET'); | ||
275 | + if ($result['ret']) { | ||
276 | + $msg = (array)json_decode($result['msg'], true); | ||
277 | + if (isset($msg['access_token'])) { | ||
278 | + $token = $msg['access_token']; | ||
279 | + Session::set('wechat_access_token', $token, $msg['expires_in'] - 1); | ||
280 | + } | ||
281 | + } | ||
282 | + } | ||
283 | + return $token; | ||
284 | + } | ||
285 | + | ||
286 | + /** | ||
287 | + * 根据Openid获取用户信息 | ||
288 | + * @param string $openid 微信OpenID | ||
289 | + * @return User|null | ||
290 | + */ | ||
291 | + public static function getUserByOpenid($openid) | ||
292 | + { | ||
293 | + $third = Third::where('platform', 'wechat')->where('openid', $openid)->find(); | ||
294 | + if ($third && $third->user_id) { | ||
295 | + return User::get($third->user_id); | ||
296 | + } | ||
297 | + return null; | ||
298 | + } | ||
299 | + | ||
300 | +} |
addons/wechat/info.ini
0 → 100644
addons/wechat/install.sql
0 → 100644
1 | + | ||
2 | +CREATE TABLE IF NOT EXISTS `__PREFIX__wechat_autoreply` ( | ||
3 | + `id` int(10) NOT NULL AUTO_INCREMENT, | ||
4 | + `title` varchar(100) NOT NULL DEFAULT '' COMMENT '标题', | ||
5 | + `text` varchar(100) NOT NULL DEFAULT '' COMMENT '触发文本', | ||
6 | + `eventkey` varchar(50) NOT NULL DEFAULT '' COMMENT '响应事件', | ||
7 | + `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注', | ||
8 | + `weigh` int(10) NOT NULL DEFAULT '0' COMMENT '权重', | ||
9 | + `createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间', | ||
10 | + `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', | ||
11 | + `status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态', | ||
12 | + PRIMARY KEY (`id`), | ||
13 | + KEY `eventkey` (`eventkey`) | ||
14 | +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='微信自动回复表'; | ||
15 | + | ||
16 | +BEGIN; | ||
17 | +INSERT INTO `__PREFIX__wechat_autoreply`(`id`, `title`, `text`, `eventkey`, `remark`, `weigh`, `createtime`, `updatetime`, `status`) VALUES (1, '输入hello', 'hello', '58c7d908c4570', '', 1, 1493366855, 1493366855, 'normal'); | ||
18 | +INSERT INTO `__PREFIX__wechat_autoreply`(`id`, `title`, `text`, `eventkey`, `remark`, `weigh`, `createtime`, `updatetime`, `status`) VALUES (2, '输入你好', '你好', '58fdfaa9e1965', '', 2, 1493704976, 1493704976, 'normal'); | ||
19 | +COMMIT; | ||
20 | + | ||
21 | +CREATE TABLE IF NOT EXISTS `__PREFIX__wechat_captcha` ( | ||
22 | + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
23 | + `event` varchar(100) DEFAULT '' COMMENT '事件', | ||
24 | + `openid` varchar(255) DEFAULT NULL COMMENT '用户openid', | ||
25 | + `context` varchar(20) DEFAULT NULL COMMENT '上下文', | ||
26 | + `code` varchar(30) DEFAULT NULL COMMENT '验证码', | ||
27 | + `times` int(10) unsigned DEFAULT '0' COMMENT '验证次数', | ||
28 | + `ip` varchar(50) DEFAULT '' COMMENT 'IP', | ||
29 | + `createtime` int(10) DEFAULT NULL COMMENT '创建时间', | ||
30 | + PRIMARY KEY (`id`), | ||
31 | + KEY `ip` (`ip`,`event`) USING BTREE, | ||
32 | + KEY `openid` (`openid`(191),`event`) | ||
33 | +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='微信公众号验证码'; | ||
34 | + | ||
35 | +CREATE TABLE IF NOT EXISTS `__PREFIX__wechat_config` ( | ||
36 | + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
37 | + `name` varchar(50) NOT NULL DEFAULT '' COMMENT '配置名称', | ||
38 | + `title` varchar(50) NOT NULL DEFAULT '' COMMENT '配置标题', | ||
39 | + `value` text NOT NULL COMMENT '配置值', | ||
40 | + `createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', | ||
41 | + `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', | ||
42 | + PRIMARY KEY (`id`), | ||
43 | + UNIQUE KEY `name` (`name`) USING BTREE | ||
44 | +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='微信配置表'; | ||
45 | + | ||
46 | +BEGIN; | ||
47 | +INSERT INTO `__PREFIX__wechat_config` VALUES ('1', 'menu', '微信菜单', '[{\"name\":\"FastAdmin\",\"sub_button\":[{\"name\":\"官网\",\"type\":\"view\",\"url\":\"http:\\/\\/www.fastadmin.net\"},{\"name\":\"在线演示\",\"type\":\"click\",\"key\":\"\"},{\"name\":\"文档\",\"type\":\"view\",\"url\":\"http:\\/\\/doc.fastadmin.net\"}]},{\"name\":\"在线客服\",\"type\":\"click\",\"key\":\"58cb852984970\"},{\"name\":\"关于我们\",\"type\":\"click\",\"key\":\"58bf944aa0777\"}]', '1497398820', '1500538185'), ('2', 'service', '客服配置', '{\"onlinetime\":\"09:00-18:00\",\"offlinemsg\":\"请在工作时间联系客服!\",\"nosessionmsg\":\"当前没有客服在线!请稍后重试!\",\"waitformsg\":\"请问有什么可以帮到您?\"}', '1497429674', '1497429674'), ('3', 'signin', '连续登录配置', '{\"s1\":\"100\",\"s2\":\"200\",\"s3\":\"300\",\"sn\":\"500\"}', '1497429711', '1497429711'); | ||
48 | +COMMIT; | ||
49 | + | ||
50 | +CREATE TABLE IF NOT EXISTS `__PREFIX__wechat_context` ( | ||
51 | + `id` int(10) NOT NULL AUTO_INCREMENT, | ||
52 | + `openid` varchar(64) NOT NULL DEFAULT '', | ||
53 | + `type` varchar(30) NOT NULL DEFAULT '' COMMENT '类型', | ||
54 | + `eventkey` varchar(64) NOT NULL DEFAULT '', | ||
55 | + `command` varchar(64) NOT NULL DEFAULT '', | ||
56 | + `message` varchar(255) NOT NULL DEFAULT '' COMMENT '内容', | ||
57 | + `refreshtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后刷新时间', | ||
58 | + `createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', | ||
59 | + `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', | ||
60 | + PRIMARY KEY (`id`), | ||
61 | + KEY `openid` (`openid`,`eventkey`) USING BTREE | ||
62 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='微信上下文表'; | ||
63 | + | ||
64 | +CREATE TABLE IF NOT EXISTS `__PREFIX__wechat_response` ( | ||
65 | + `id` int(10) NOT NULL AUTO_INCREMENT, | ||
66 | + `title` varchar(100) NOT NULL DEFAULT '' COMMENT '资源名', | ||
67 | + `eventkey` varchar(128) NOT NULL DEFAULT '' COMMENT '事件', | ||
68 | + `type` enum('text','image','news','voice','video','music','link','app') NOT NULL DEFAULT 'text' COMMENT '类型', | ||
69 | + `content` text NOT NULL COMMENT '内容', | ||
70 | + `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注', | ||
71 | + `createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', | ||
72 | + `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', | ||
73 | + `status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态', | ||
74 | + PRIMARY KEY (`id`), | ||
75 | + UNIQUE KEY `eventkey` (`eventkey`) USING BTREE | ||
76 | +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='微信资源表'; | ||
77 | + | ||
78 | +BEGIN; | ||
79 | +INSERT INTO `__PREFIX__wechat_response` VALUES ('1', '签到送积分', '58adaf7876aab', 'app', '{\"app\":\"signin\"}', '', '1487777656', '1487777656', 'normal'), ('2', '关于我们', '58bf944aa0777', 'app', '{\"app\":\"page\",\"id\":\"1\"}', '', '1488950346', '1488950346', 'normal'), ('3', '自动回复1', '58c7d908c4570', 'text', '{\"content\":\"world\"}', '', '1489492232', '1489492232', 'normal'), ('5', '自动回复2', '58fdfaa9e1965', 'text', '{\"content\":\"我是FastAdmin!\"}', '', '1493039785', '1493039785', 'normal'); | ||
80 | +COMMIT; | ||
81 | + |
addons/wechat/library/Config.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat\library; | ||
4 | + | ||
5 | +/** | ||
6 | + * 微信配置类 | ||
7 | + */ | ||
8 | +class Config | ||
9 | +{ | ||
10 | + | ||
11 | + public static function load() | ||
12 | + { | ||
13 | + $config = get_addon_config('wechat'); | ||
14 | + | ||
15 | + return [ | ||
16 | + /** | ||
17 | + * 账号基本信息,请从微信公众平台/开放平台获取 | ||
18 | + */ | ||
19 | + 'app_id' => $config['app_id'], // AppID | ||
20 | + 'secret' => $config['secret'], // AppSecret | ||
21 | + 'token' => $config['token'], // Token | ||
22 | + 'aes_key' => $config['aes_key'], // EncodingAESKey,安全模式下请一定要填写!!! | ||
23 | + | ||
24 | + /** | ||
25 | + * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 | ||
26 | + * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例 | ||
27 | + */ | ||
28 | + 'response_type' => 'array', | ||
29 | + | ||
30 | + /** | ||
31 | + * 日志配置 | ||
32 | + * | ||
33 | + * level: 日志级别, 可选为:debug/info/notice/warning/error/critical/alert/emergency | ||
34 | + * path:日志文件位置(绝对路径!!!),要求可写权限 | ||
35 | + */ | ||
36 | + 'log' => [ | ||
37 | + 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod | ||
38 | + 'channels' => [ | ||
39 | + // 测试环境 | ||
40 | + 'dev' => [ | ||
41 | + 'driver' => 'single', | ||
42 | + 'path' => ROOT_PATH . '/runtime/log/easywechat.log', | ||
43 | + 'level' => 'debug', | ||
44 | + ], | ||
45 | + // 生产环境 | ||
46 | + 'prod' => [ | ||
47 | + 'driver' => 'daily', | ||
48 | + 'path' => ROOT_PATH . '/runtime/log/easywechat.log', | ||
49 | + 'level' => $config['log_level'], | ||
50 | + ], | ||
51 | + ], | ||
52 | + ], | ||
53 | + | ||
54 | + /** | ||
55 | + * 接口请求相关配置,超时时间等,具体可用参数请参考: | ||
56 | + * http://docs.guzzlephp.org/en/stable/request-config.html | ||
57 | + * | ||
58 | + * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。 | ||
59 | + * - retry_delay: 重试延迟间隔(单位:ms),默认 500 | ||
60 | + * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php | ||
61 | + */ | ||
62 | + 'http' => [ | ||
63 | + 'max_retries' => 1, | ||
64 | + 'retry_delay' => 500, | ||
65 | + 'timeout' => 5.0, | ||
66 | + // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri | ||
67 | + ], | ||
68 | + | ||
69 | + /** | ||
70 | + * OAuth 配置 | ||
71 | + * | ||
72 | + * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login | ||
73 | + * callback:OAuth授权完成后的回调页地址 | ||
74 | + */ | ||
75 | + 'oauth' => [ | ||
76 | + 'scopes' => ['snsapi_userinfo'], | ||
77 | + 'callback' => $config['oauth_callback'], | ||
78 | + ], | ||
79 | + ]; | ||
80 | + } | ||
81 | + | ||
82 | +} |
addons/wechat/library/Wechat.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat\library; | ||
4 | + | ||
5 | +use addons\signin\model\Signin; | ||
6 | +use addons\third\model\Third; | ||
7 | +use app\common\model\User; | ||
8 | +use EasyWeChat\Kernel\Messages\News; | ||
9 | +use EasyWeChat\Kernel\Messages\NewsItem; | ||
10 | +use fast\Date; | ||
11 | +use fast\Http; | ||
12 | +use fast\Random; | ||
13 | +use think\Session; | ||
14 | +use think\Config; | ||
15 | + | ||
16 | +/** | ||
17 | + * 微信服务类 | ||
18 | + */ | ||
19 | +class Wechat | ||
20 | +{ | ||
21 | + public static function appConfig() | ||
22 | + { | ||
23 | + return array( | ||
24 | + 'signin' => array( | ||
25 | + 'name' => '签到送积分', | ||
26 | + 'config' => array() | ||
27 | + ), | ||
28 | + 'blog' => array( | ||
29 | + 'name' => '关联博客', | ||
30 | + 'config' => array( | ||
31 | + array( | ||
32 | + 'type' => 'text', | ||
33 | + 'caption' => '日志ID', | ||
34 | + 'field' => 'post_id', | ||
35 | + 'rule' => '', | ||
36 | + 'extend' => 'class="form-control selectpage" data-source="blog/post/index" data-field="title"', | ||
37 | + 'options' => '', | ||
38 | + ), | ||
39 | + array( | ||
40 | + 'type' => 'radio', | ||
41 | + 'caption' => '开启搜索日志', | ||
42 | + 'field' => 'searchpost', | ||
43 | + 'rule' => '', | ||
44 | + 'extend' => '', | ||
45 | + 'options' => [ | ||
46 | + '1' => '是', | ||
47 | + '0' => '否', | ||
48 | + ], | ||
49 | + ), | ||
50 | + array( | ||
51 | + 'type' => 'text', | ||
52 | + 'caption' => '正则搜索匹配索引', | ||
53 | + 'field' => 'searchregexindex', | ||
54 | + 'rule' => '', | ||
55 | + 'defaultvalue' => '1', | ||
56 | + 'extend' => '', | ||
57 | + 'options' => [], | ||
58 | + ) | ||
59 | + ) | ||
60 | + ), | ||
61 | + 'cms' => array( | ||
62 | + 'name' => '关联CMS', | ||
63 | + 'config' => array( | ||
64 | + array( | ||
65 | + 'type' => 'text', | ||
66 | + 'caption' => '文章ID', | ||
67 | + 'field' => 'archives_id', | ||
68 | + 'rule' => '', | ||
69 | + 'extend' => 'class="form-control selectpage" data-source="cms/archives/index" data-field="title"', | ||
70 | + 'options' => '' | ||
71 | + ), | ||
72 | + array( | ||
73 | + 'type' => 'text', | ||
74 | + 'caption' => '单页ID', | ||
75 | + 'field' => 'page_id', | ||
76 | + 'rule' => '', | ||
77 | + 'extend' => 'class="form-control selectpage" data-source="cms/page/index" data-field="title"', | ||
78 | + 'options' => '' | ||
79 | + ), | ||
80 | + array( | ||
81 | + 'type' => 'text', | ||
82 | + 'caption' => '专题ID', | ||
83 | + 'field' => 'special_id', | ||
84 | + 'rule' => '', | ||
85 | + 'extend' => 'class="form-control selectpage" data-source="cms/special/index" data-field="title"', | ||
86 | + 'options' => '' | ||
87 | + ), | ||
88 | + array( | ||
89 | + 'type' => 'radio', | ||
90 | + 'caption' => '开启搜索文章', | ||
91 | + 'field' => 'searcharchives', | ||
92 | + 'rule' => '', | ||
93 | + 'extend' => '', | ||
94 | + 'options' => [ | ||
95 | + '1' => '是', | ||
96 | + '0' => '否', | ||
97 | + ], | ||
98 | + ), | ||
99 | + array( | ||
100 | + 'type' => 'radio', | ||
101 | + 'caption' => '开启搜索单页', | ||
102 | + 'field' => 'searchpage', | ||
103 | + 'rule' => '', | ||
104 | + 'extend' => '', | ||
105 | + 'options' => [ | ||
106 | + '1' => '是', | ||
107 | + '0' => '否', | ||
108 | + ], | ||
109 | + ), | ||
110 | + array( | ||
111 | + 'type' => 'radio', | ||
112 | + 'caption' => '开启搜索专题', | ||
113 | + 'field' => 'searchspecial', | ||
114 | + 'rule' => '', | ||
115 | + 'extend' => '', | ||
116 | + 'options' => [ | ||
117 | + '1' => '是', | ||
118 | + '0' => '否', | ||
119 | + ], | ||
120 | + ), | ||
121 | + array( | ||
122 | + 'type' => 'text', | ||
123 | + 'caption' => '正则搜索匹配索引', | ||
124 | + 'field' => 'searchregexindex', | ||
125 | + 'rule' => '', | ||
126 | + 'defaultvalue' => '1', | ||
127 | + 'extend' => '', | ||
128 | + 'options' => [], | ||
129 | + ) | ||
130 | + ) | ||
131 | + ), | ||
132 | + 'ask' => array( | ||
133 | + 'name' => '关联问答', | ||
134 | + 'config' => array( | ||
135 | + array( | ||
136 | + 'type' => 'text', | ||
137 | + 'caption' => '问题ID', | ||
138 | + 'field' => 'question_id', | ||
139 | + 'extend' => 'class="form-control selectpage" data-source="ask/question/index" data-field="title"', | ||
140 | + 'options' => '' | ||
141 | + ), | ||
142 | + array( | ||
143 | + 'type' => 'text', | ||
144 | + 'caption' => '文章ID', | ||
145 | + 'field' => 'article_id', | ||
146 | + 'extend' => 'class="form-control selectpage" data-source="ask/article/index" data-field="title"', | ||
147 | + 'options' => '' | ||
148 | + ), | ||
149 | + array( | ||
150 | + 'type' => 'radio', | ||
151 | + 'caption' => '开启搜索问题', | ||
152 | + 'field' => 'searchquestion', | ||
153 | + 'rule' => '', | ||
154 | + 'extend' => '', | ||
155 | + 'options' => [ | ||
156 | + '1' => '是', | ||
157 | + '0' => '否', | ||
158 | + ], | ||
159 | + ), | ||
160 | + array( | ||
161 | + 'type' => 'radio', | ||
162 | + 'caption' => '开启搜索文章', | ||
163 | + 'field' => 'searcharticle', | ||
164 | + 'rule' => '', | ||
165 | + 'extend' => '', | ||
166 | + 'options' => [ | ||
167 | + '1' => '是', | ||
168 | + '0' => '否', | ||
169 | + ], | ||
170 | + ), | ||
171 | + array( | ||
172 | + 'type' => 'text', | ||
173 | + 'caption' => '正则搜索匹配索引', | ||
174 | + 'field' => 'searchregexindex', | ||
175 | + 'rule' => '', | ||
176 | + 'defaultvalue' => '1', | ||
177 | + 'extend' => '', | ||
178 | + 'options' => [], | ||
179 | + ) | ||
180 | + ) | ||
181 | + ), | ||
182 | + 'vote' => array( | ||
183 | + 'name' => '关联投票', | ||
184 | + 'config' => array( | ||
185 | + array( | ||
186 | + 'type' => 'text', | ||
187 | + 'caption' => '投票主题ID', | ||
188 | + 'field' => 'subject_id', | ||
189 | + 'extend' => 'class="form-control selectpage" data-source="vote/subject/index" data-field="title"', | ||
190 | + 'rule' => '', | ||
191 | + 'options' => '' | ||
192 | + ), | ||
193 | + array( | ||
194 | + 'type' => 'text', | ||
195 | + 'caption' => '参赛人员ID', | ||
196 | + 'field' => 'player_id', | ||
197 | + 'rule' => '', | ||
198 | + 'extend' => 'class="form-control selectpage" data-source="vote/player/index" data-field="nickname"', | ||
199 | + 'options' => '' | ||
200 | + ), | ||
201 | + array( | ||
202 | + 'type' => 'radio', | ||
203 | + 'caption' => '开启搜索主题', | ||
204 | + 'field' => 'searchsubject', | ||
205 | + 'rule' => '', | ||
206 | + 'extend' => '', | ||
207 | + 'options' => [ | ||
208 | + '1' => '是', | ||
209 | + '0' => '否', | ||
210 | + ], | ||
211 | + ), | ||
212 | + array( | ||
213 | + 'type' => 'radio', | ||
214 | + 'caption' => '开启搜索参赛人员', | ||
215 | + 'field' => 'searchplayer', | ||
216 | + 'rule' => '', | ||
217 | + 'extend' => '', | ||
218 | + 'options' => [ | ||
219 | + '1' => '是', | ||
220 | + '0' => '否', | ||
221 | + ], | ||
222 | + ), | ||
223 | + array( | ||
224 | + 'type' => 'text', | ||
225 | + 'caption' => '正则搜索匹配索引', | ||
226 | + 'field' => 'searchregexindex', | ||
227 | + 'rule' => '', | ||
228 | + 'defaultvalue' => '1', | ||
229 | + 'extend' => '', | ||
230 | + 'options' => [], | ||
231 | + ) | ||
232 | + ) | ||
233 | + ), | ||
234 | + ); | ||
235 | + } | ||
236 | + | ||
237 | + /** | ||
238 | + * 应用交互 | ||
239 | + * @return array|bool|mixed|string | ||
240 | + */ | ||
241 | + public function response($obj, $openid, $message, $content, $context, $matches = null) | ||
242 | + { | ||
243 | + $response = false; | ||
244 | + if (isset($content['app'])) { | ||
245 | + $entry = null; | ||
246 | + $keyword = isset($content['searchregexindex']) && $content['searchregexindex'] > -1 && $matches && isset($matches[$content['searchregexindex']]) | ||
247 | + ? $matches[$content['searchregexindex']] : $message; | ||
248 | + switch ($content['app']) { | ||
249 | + case 'signin': | ||
250 | + $signinInfo = get_addon_info('signin'); | ||
251 | + if (!$signinInfo || !$signinInfo['state']) { | ||
252 | + return "请先在后台管理安装并启用《会员签到》插件"; | ||
253 | + } | ||
254 | + $thirdInfo = get_addon_info('third'); | ||
255 | + if (!$thirdInfo || !$thirdInfo['state']) { | ||
256 | + return "请先在后台管理安装并启用《第三方登录》插件"; | ||
257 | + } | ||
258 | + $user = self::getUserByOpenid($openid); | ||
259 | + if (!$user) { | ||
260 | + return "请先在会员中心绑定微信登录,<a href='" . addon_url('third/index/connect', [':platform' => 'wechat'], true, true) . "'>点击这里绑定</a>"; | ||
261 | + } | ||
262 | + $config = get_addon_config('signin'); | ||
263 | + $signdata = $config['signinscore']; | ||
264 | + $lastdata = Signin::where('user_id', $user->id)->order('id', 'desc')->find(); | ||
265 | + $successions = $lastdata && $lastdata['createtime'] > Date::unixtime('day', -1) ? $lastdata['successions'] : 0; | ||
266 | + $signin = Signin::where('user_id', $user->id)->whereTime('createtime', 'today')->find(); | ||
267 | + if ($signin) { | ||
268 | + return '今天已签到,请明天再来!'; | ||
269 | + } else { | ||
270 | + $successions++; | ||
271 | + Signin::create(['user_id' => $user->id, 'successions' => $successions, 'createtime' => time()]); | ||
272 | + $score = isset($signdata['s' . $successions]) ? $signdata['s' . $successions] : $signdata['sn']; | ||
273 | + | ||
274 | + $user->setInc('score', $score); | ||
275 | + User::score($score, $user->id, "连续签到{$successions}天"); | ||
276 | + return '签到成功!连续签到' . $successions . '天!获得' . $score . '积分,'; | ||
277 | + } | ||
278 | + break; | ||
279 | + case 'blog': | ||
280 | + $blogInfo = get_addon_info('blog'); | ||
281 | + if (!$blogInfo || !$blogInfo['state']) { | ||
282 | + return "请先在后台管理安装并启用《简单博客》插件"; | ||
283 | + } | ||
284 | + $entry = \addons\blog\model\Post::get($content['post_id']); | ||
285 | + if ($entry) { | ||
286 | + $entry['image'] = $entry['thumb']; | ||
287 | + } | ||
288 | + if (!$entry && $content['searchpost']) { | ||
289 | + $entry = \addons\blog\model\Post::where("title|description", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
290 | + } | ||
291 | + if (!$entry) { | ||
292 | + return "未搜索到任何匹配信息$keyword" . json_encode($matches); | ||
293 | + } | ||
294 | + break; | ||
295 | + case 'cms': | ||
296 | + $cmsInfo = get_addon_info('cms'); | ||
297 | + if (!$cmsInfo || !$cmsInfo['state']) { | ||
298 | + return "请先在后台管理安装并启用《CMS内容管理系统》插件"; | ||
299 | + } | ||
300 | + if (isset($content['archives_id']) && $content['archives_id']) { | ||
301 | + $entry = \addons\cms\model\Archives::get($content['archives_id']); | ||
302 | + } elseif (isset($content['page_id']) && $content['page_id']) { | ||
303 | + $entry = \addons\cms\model\Page::get($content['page_id']); | ||
304 | + } elseif (isset($content['special_id']) && $content['special_id']) { | ||
305 | + $entry = \addons\cms\model\Special::get($content['special_id']); | ||
306 | + } | ||
307 | + if (!$entry && $content['searcharchives']) { | ||
308 | + $entry = \addons\cms\model\Archives::where("title|description", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
309 | + } | ||
310 | + if (!$entry && $content['searchpage']) { | ||
311 | + $entry = \addons\cms\model\Page::where("title|description", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
312 | + } | ||
313 | + if (!$entry && $content['searchspecial']) { | ||
314 | + $entry = \addons\cms\model\Special::where("title|description", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
315 | + } | ||
316 | + if (!$entry) { | ||
317 | + return "未搜索到任何匹配信息"; | ||
318 | + } | ||
319 | + break; | ||
320 | + case 'ask': | ||
321 | + $blogInfo = get_addon_info('ask'); | ||
322 | + if (!$blogInfo || !$blogInfo['state']) { | ||
323 | + return "请先在后台管理安装并启用《知识付费问答》插件"; | ||
324 | + } | ||
325 | + | ||
326 | + if (isset($content['question_id']) && $content['question_id']) { | ||
327 | + $entry = \addons\ask\model\Question::get($content['question_id']); | ||
328 | + } elseif (isset($content['article_id']) && $content['article_id']) { | ||
329 | + $entry = \addons\ask\model\Article::get($content['article_id']); | ||
330 | + } | ||
331 | + | ||
332 | + if (!$entry && $content['searchquestion']) { | ||
333 | + $entry = \addons\ask\model\Question::where("title", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
334 | + } | ||
335 | + if (!$entry && $content['searcharticle']) { | ||
336 | + $entry = \addons\ask\model\Article::where("title|description", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
337 | + } | ||
338 | + if (!$entry) { | ||
339 | + return "未搜索到任何匹配信息"; | ||
340 | + } | ||
341 | + break; | ||
342 | + case 'vote': | ||
343 | + $blogInfo = get_addon_info('vote'); | ||
344 | + if (!$blogInfo || !$blogInfo['state']) { | ||
345 | + return "请先在后台管理安装并启用《在线投票系统》插件"; | ||
346 | + } | ||
347 | + if (isset($content['subject_id']) && $content['subject_id']) { | ||
348 | + $entry = \addons\vote\model\Subject::all($content['subject_id']); | ||
349 | + } elseif (isset($content['player_id']) && $content['player_id']) { | ||
350 | + $entry = \addons\vote\model\Player::all($content['player_id']); | ||
351 | + } | ||
352 | + | ||
353 | + if (!$entry && $content['searchsubject']) { | ||
354 | + $entry = \addons\vote\model\Subject::where("title|description", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
355 | + } | ||
356 | + if (!$entry && $content['searchplayer']) { | ||
357 | + $entry = \addons\vote\model\Player::where("nickname", 'like', "%{$keyword}%")->where('status', 'normal')->find(); | ||
358 | + } | ||
359 | + | ||
360 | + if (!$entry) { | ||
361 | + return "未搜索到任何匹配信息"; | ||
362 | + } | ||
363 | + break; | ||
364 | + default: | ||
365 | + break; | ||
366 | + } | ||
367 | + if (isset($entry) && $entry) { | ||
368 | + $items = [ | ||
369 | + new NewsItem([ | ||
370 | + 'title' => isset($entry['title']) ? $entry['title'] : (isset($entry['nickname']) ? $entry['nickname'] : ''), | ||
371 | + 'description' => isset($entry['description']) ? $entry['description'] : '', | ||
372 | + 'url' => $entry['fullurl'], | ||
373 | + 'image' => cdnurl($entry['image'], true), | ||
374 | + ]), | ||
375 | + ]; | ||
376 | + $news = new News($items); | ||
377 | + | ||
378 | + $response[] = $news; | ||
379 | + } | ||
380 | + } else { | ||
381 | + $response = isset($content['content']) ? $content['content'] : $response; | ||
382 | + } | ||
383 | + return $response; | ||
384 | + } | ||
385 | + | ||
386 | + /** | ||
387 | + * 获取Token | ||
388 | + */ | ||
389 | + public static function getAccessToken() | ||
390 | + { | ||
391 | + $token = Session::get('wechat_access_token'); | ||
392 | + if (!$token) { | ||
393 | + $config = get_addon_config('wechat'); | ||
394 | + $params = [ | ||
395 | + 'grant_type' => 'client_credential', | ||
396 | + 'appid' => $config['app_id'], | ||
397 | + 'secret' => $config['secret'], | ||
398 | + ]; | ||
399 | + $url = "https://api.weixin.qq.com/cgi-bin/token"; | ||
400 | + $result = Http::sendRequest($url, $params, 'GET'); | ||
401 | + if ($result['ret']) { | ||
402 | + $msg = (array)json_decode($result['msg'], true); | ||
403 | + if (isset($msg['access_token'])) { | ||
404 | + $token = $msg['access_token']; | ||
405 | + Session::set('wechat_access_token', $token, $msg['expires_in'] - 1); | ||
406 | + } | ||
407 | + } | ||
408 | + } | ||
409 | + return $token; | ||
410 | + } | ||
411 | + | ||
412 | + /** | ||
413 | + * 根据Openid获取用户信息 | ||
414 | + * @param string $openid 微信OpenID | ||
415 | + * @return User|null | ||
416 | + */ | ||
417 | + public static function getUserByOpenid($openid) | ||
418 | + { | ||
419 | + $third = Third::where('platform', 'wechat')->where('openid', $openid)->find(); | ||
420 | + if ($third && $third->user_id) { | ||
421 | + return User::get($third->user_id); | ||
422 | + } | ||
423 | + return null; | ||
424 | + } | ||
425 | +} |
addons/wechat/model/WechatAutoreply.php
0 → 100644
addons/wechat/model/WechatCaptcha.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat\model; | ||
4 | + | ||
5 | +use fast\Random; | ||
6 | +use think\Model; | ||
7 | + | ||
8 | +class WechatCaptcha extends Model | ||
9 | +{ | ||
10 | + | ||
11 | + // 表名 | ||
12 | + protected $name = 'wechat_captcha'; | ||
13 | + // 自动写入时间戳字段 | ||
14 | + protected $autoWriteTimestamp = 'int'; | ||
15 | + // 定义时间戳字段名 | ||
16 | + protected $createTime = 'createtime'; | ||
17 | + protected $updateTime = ''; | ||
18 | + // 追加属性 | ||
19 | + protected $append = [ | ||
20 | + ]; | ||
21 | + | ||
22 | + /** | ||
23 | + * 发送验证码 | ||
24 | + * @param $openid string 用户OpenID | ||
25 | + * @param $event string 事件 | ||
26 | + * @param $ip string IP地址 | ||
27 | + * @return string | ||
28 | + */ | ||
29 | + public static function send($openid, $event, $ip) | ||
30 | + { | ||
31 | + $captcha = self::where(['openid' => $openid, 'event' => $event])->whereTime('createtime', '-2 minutes')->find(); | ||
32 | + if ($captcha) { | ||
33 | + return "验证码发送速度过快,请稍后重试"; | ||
34 | + } | ||
35 | + $code = Random::alnum(4); | ||
36 | + $data = [ | ||
37 | + 'event' => $event, | ||
38 | + 'openid' => $openid, | ||
39 | + 'code' => $code, | ||
40 | + 'ip' => $ip, | ||
41 | + ]; | ||
42 | + self::create($data); | ||
43 | + return "你的验证码是:{$code},2分钟内输入有效"; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * 检测验证码 | ||
48 | + * @param $code string 验证码 | ||
49 | + * @param $event string 事件 | ||
50 | + * @param $ip string IP | ||
51 | + * @return bool | ||
52 | + */ | ||
53 | + public static function check($code, $event, $ip = null) | ||
54 | + { | ||
55 | + $ip = is_null($ip) ? request()->ip() : $ip; | ||
56 | + $captcha = self::where(['ip' => $ip, 'event' => $event])->whereTime('createtime', '-2 minutes')->find(); | ||
57 | + if ($captcha && $captcha->code == $code && $captcha->times < 10) { | ||
58 | + $captcha->setInc("times"); | ||
59 | + return true; | ||
60 | + } | ||
61 | + //验证大于10次或超时 | ||
62 | + if ($captcha && ($captcha->times >= 10 || time() - $captcha->createtime > 120)) { | ||
63 | + $captcha->delete(); | ||
64 | + } | ||
65 | + | ||
66 | + return false; | ||
67 | + } | ||
68 | + | ||
69 | +} |
addons/wechat/model/WechatConfig.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\wechat\model; | ||
4 | + | ||
5 | +use think\Model; | ||
6 | + | ||
7 | +class WechatConfig extends Model | ||
8 | +{ | ||
9 | + | ||
10 | + // 表名,不含前缀 | ||
11 | + public $name = 'wechat_config'; | ||
12 | + // 自动写入时间戳字段 | ||
13 | + protected $autoWriteTimestamp = 'int'; | ||
14 | + // 定义时间戳字段名 | ||
15 | + protected $createTime = 'createtime'; | ||
16 | + protected $updateTime = 'updatetime'; | ||
17 | + // 追加属性 | ||
18 | + protected $append = [ | ||
19 | + ]; | ||
20 | + | ||
21 | + /** | ||
22 | + * 读取指定配置名称的值 | ||
23 | + * @param string $name | ||
24 | + * @return string | ||
25 | + */ | ||
26 | + public static function getValue($name) | ||
27 | + { | ||
28 | + $item = self::get(['name' => $name]); | ||
29 | + return $item ? $item->value : ''; | ||
30 | + } | ||
31 | + | ||
32 | +} |
addons/wechat/model/WechatContext.php
0 → 100644
addons/wechat/model/WechatResponse.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 用户信用管理 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Agentcredit extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Agentcredit模型对象 | ||
18 | + * @var \app\admin\model\agent\Agentcredit | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Agentcredit; | ||
26 | + $this->view->assign("acTypeList", $this->model->getAcTypeList()); | ||
27 | + $this->view->assign("acStuList", $this->model->getAcStuList()); | ||
28 | + $actype = $this->request->param('actype', 0);//分类 | ||
29 | + //选择的企业id | ||
30 | + $agentListIds = $this->request->param('ids', 0); | ||
31 | + if ($actype == 0) { | ||
32 | + $ginfo = Db::name('agent_list') | ||
33 | + ->where(['id' => $agentListIds]) | ||
34 | + ->find(); | ||
35 | + } else { | ||
36 | + $ginfo = []; | ||
37 | + } | ||
38 | + //门店信息 | ||
39 | + if ($actype == 1) { | ||
40 | + $sinfo = Db::name('agent_shop') | ||
41 | + ->where(['id' => $agentListIds]) | ||
42 | + ->find(); | ||
43 | + //门店所属企业信息 | ||
44 | + $ginfo = Db::name('agent_list') | ||
45 | + ->where(['id' => $sinfo['agent_list_id']]) | ||
46 | + ->find(); | ||
47 | + } else { | ||
48 | + $sinfo = []; | ||
49 | + } | ||
50 | + //经纪人信息 | ||
51 | + if ($actype == 2) { | ||
52 | + $jinfo = Db::name('agent_users') | ||
53 | + ->where(['id' => $agentListIds]) | ||
54 | + ->find(); | ||
55 | + //所属企业信息 | ||
56 | + $ginfo = Db::name('agent_list') | ||
57 | + ->where(['id' => $jinfo['agent_list_id']]) | ||
58 | + ->find(); | ||
59 | + //所属门店 | ||
60 | + $sinfo = Db::name('agent_shop') | ||
61 | + ->where(['id' => $jinfo['agent_shop_id']]) | ||
62 | + ->find(); | ||
63 | + } else { | ||
64 | + $jinfo = []; | ||
65 | + } | ||
66 | + $this->view->assign("ginfo", $ginfo); | ||
67 | + $this->view->assign("sinfo", $sinfo); | ||
68 | + $this->view->assign("jinfo", $jinfo); | ||
69 | + $this->view->assign('actype', $actype); | ||
70 | + } | ||
71 | + | ||
72 | + | ||
73 | + /** | ||
74 | + * 查看 | ||
75 | + */ | ||
76 | + public function index() | ||
77 | + { | ||
78 | + //当前是否为关联查询 | ||
79 | + $this->relationSearch = false; | ||
80 | + //设置过滤方法 | ||
81 | + $this->request->filter(['strip_tags', 'trim']); | ||
82 | + if ($this->request->isAjax()) { | ||
83 | + $actype = $this->request->param('actype', 0);//分类 | ||
84 | + $ids = $this->request->param('ids', 0); | ||
85 | + if ($actype == 0) { | ||
86 | + $wh['agent_list_id'] = ['=', $ids]; | ||
87 | + } | ||
88 | + if ($actype == 1) { | ||
89 | + $wh['agent_shop_id'] = ['=', $ids]; | ||
90 | + } | ||
91 | + if ($actype == 2) { | ||
92 | + $wh['agent_user_id'] = ['=', $ids]; | ||
93 | + } | ||
94 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
95 | + if ($this->request->request('keyField')) { | ||
96 | + return $this->selectpage(); | ||
97 | + } | ||
98 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
99 | + | ||
100 | + $list = $this->model | ||
101 | + ->where($where) | ||
102 | + ->where($wh) | ||
103 | + ->order($sort, $order) | ||
104 | + ->paginate($limit); | ||
105 | + | ||
106 | + $rows = $list->items(); | ||
107 | + foreach ($rows as $kk => $vv) { | ||
108 | + //关联企业、门店、经纪人信息 | ||
109 | + $ginfo = Db::name('agent_list') | ||
110 | + ->where(['id' => $vv['agent_list_id']]) | ||
111 | + ->field('id,agent_name') | ||
112 | + ->find(); | ||
113 | + $rows[$kk]['agent_name'] = $ginfo['agent_name'] ? $ginfo['agent_name'] : '-'; | ||
114 | + | ||
115 | + $sinfo = Db::name('agent_shop') | ||
116 | + ->where(['id' => $vv['agent_shop_id']]) | ||
117 | + ->field('id,shop_name') | ||
118 | + ->find(); | ||
119 | + $rows[$kk]['shop_name'] = $sinfo['shop_name'] ? $sinfo['shop_name'] : '-'; | ||
120 | + $jinfo = Db::name('agent_users') | ||
121 | + ->where(['id' => $vv['agent_user_id']]) | ||
122 | + ->field('id,jjr_name') | ||
123 | + ->find(); | ||
124 | + $rows[$kk]['jjr_name'] = $jinfo['jjr_name'] ? $jinfo['jjr_name'] : '-'; | ||
125 | + } | ||
126 | + | ||
127 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
128 | + | ||
129 | + return json($result); | ||
130 | + } | ||
131 | + return $this->view->fetch(); | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * 添加 | ||
136 | + */ | ||
137 | + public function add() | ||
138 | + { | ||
139 | + if ($this->request->isPost()) { | ||
140 | + $params = $this->request->post("row/a"); | ||
141 | + if ($params) { | ||
142 | + $params = $this->preExcludeFields($params); | ||
143 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
144 | + $params[$this->dataLimitField] = $this->auth->id; | ||
145 | + } | ||
146 | + $result = false; | ||
147 | + Db::startTrans(); | ||
148 | + try { | ||
149 | + //是否采用模型验证 | ||
150 | + if ($this->modelValidate) { | ||
151 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
152 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
153 | + $this->model->validateFailException(true)->validate($validate); | ||
154 | + } | ||
155 | + $params['admin'] = $this->auth->id; | ||
156 | + //计算之前和之后的信用分数 | ||
157 | + if ($params['ac_type'] == 0) { | ||
158 | + if (empty($params['agent_list_id'])) { | ||
159 | + $this->error('请选择企业信息'); | ||
160 | + } | ||
161 | + //企业原信用分 | ||
162 | + $ginfo = Db::name('agent_list') | ||
163 | + ->where(['id' => $params['agent_list_id']]) | ||
164 | + ->find(); | ||
165 | + $params['change_before'] = $ginfo['credit']; | ||
166 | + $params['change_after'] = $ginfo['credit'] + $params['change_num']; | ||
167 | + } | ||
168 | + //门店的 | ||
169 | + if ($params['ac_type'] == 1) { | ||
170 | + if (empty($params['agent_list_id'])) { | ||
171 | + $this->error('请选择企业信息'); | ||
172 | + } | ||
173 | + if (empty($params['agent_shop_id'])) { | ||
174 | + $this->error('请选择门店信息'); | ||
175 | + } | ||
176 | + //原信用分 | ||
177 | + $sinfo = Db::name('agent_shop') | ||
178 | + ->where(['id' => $params['agent_shop_id']]) | ||
179 | + ->find(); | ||
180 | + $params['change_before'] = $sinfo['credit']; | ||
181 | + $params['change_after'] = $sinfo['credit'] + $params['change_num']; | ||
182 | + } | ||
183 | + //经纪人的 | ||
184 | + if ($params['ac_type'] == 2) { | ||
185 | + if (empty($params['agent_user_id'])) { | ||
186 | + $this->error('请选择经纪人信息'); | ||
187 | + } | ||
188 | + //原信用分 | ||
189 | + $jinfo = Db::name('agent_users') | ||
190 | + ->where(['id' => $params['agent_user_id']]) | ||
191 | + ->find(); | ||
192 | + $params['change_before'] = $jinfo['credit']; | ||
193 | + $params['change_after'] = $jinfo['credit'] + $params['change_num']; | ||
194 | + } | ||
195 | + $result = $this->model->allowField(true)->save($params); | ||
196 | + //更新企业、门店、经纪人表的信用分数 | ||
197 | + $agentnum['credit'] = $params['change_after']; | ||
198 | + $agentnum['updatetime'] = time(); | ||
199 | + if ($params['ac_type'] == 0) { | ||
200 | + Db::name('agent_list') | ||
201 | + ->where(['id' => $params['agent_list_id']]) | ||
202 | + ->update($agentnum); | ||
203 | + } | ||
204 | + if ($params['ac_type'] == 1) { | ||
205 | + Db::name('agent_shop') | ||
206 | + ->where(['id' => $params['agent_shop_id']]) | ||
207 | + ->update($agentnum); | ||
208 | + } | ||
209 | + if ($params['ac_type'] == 2) { | ||
210 | + Db::name('agent_users') | ||
211 | + ->where(['id' => $params['agent_user_id']]) | ||
212 | + ->update($agentnum); | ||
213 | + } | ||
214 | + Db::commit(); | ||
215 | + } catch (ValidateException $e) { | ||
216 | + Db::rollback(); | ||
217 | + $this->error($e->getMessage()); | ||
218 | + } catch (PDOException $e) { | ||
219 | + Db::rollback(); | ||
220 | + $this->error($e->getMessage()); | ||
221 | + } catch (Exception $e) { | ||
222 | + Db::rollback(); | ||
223 | + $this->error($e->getMessage()); | ||
224 | + } | ||
225 | + if ($result !== false) { | ||
226 | + $this->success(); | ||
227 | + } else { | ||
228 | + $this->error(__('No rows were inserted')); | ||
229 | + } | ||
230 | + } | ||
231 | + $this->error(__('Parameter %s can not be empty', '')); | ||
232 | + } | ||
233 | + return $this->view->fetch(); | ||
234 | + } | ||
235 | + | ||
236 | + /** | ||
237 | + * 编辑 | ||
238 | + */ | ||
239 | + public function edit($ids = null) | ||
240 | + { | ||
241 | + $row = $this->model->get($ids); | ||
242 | + if (!$row) { | ||
243 | + $this->error(__('No Results were found')); | ||
244 | + } | ||
245 | + $adminIds = $this->getDataLimitAdminIds(); | ||
246 | + if (is_array($adminIds)) { | ||
247 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
248 | + $this->error(__('You have no permission')); | ||
249 | + } | ||
250 | + } | ||
251 | + if ($this->request->isPost()) { | ||
252 | + $params = $this->request->post("row/a"); | ||
253 | + if ($params) { | ||
254 | + $params = $this->preExcludeFields($params); | ||
255 | + | ||
256 | + $result = false; | ||
257 | + Db::startTrans(); | ||
258 | + try { | ||
259 | + //是否采用模型验证 | ||
260 | + if ($this->modelValidate) { | ||
261 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
262 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
263 | + $row->validateFailException(true)->validate($validate); | ||
264 | + } | ||
265 | + $result = $row->allowField(true)->save($params); | ||
266 | + Db::commit(); | ||
267 | + } catch (ValidateException $e) { | ||
268 | + Db::rollback(); | ||
269 | + $this->error($e->getMessage()); | ||
270 | + } catch (PDOException $e) { | ||
271 | + Db::rollback(); | ||
272 | + $this->error($e->getMessage()); | ||
273 | + } catch (Exception $e) { | ||
274 | + Db::rollback(); | ||
275 | + $this->error($e->getMessage()); | ||
276 | + } | ||
277 | + if ($result !== false) { | ||
278 | + $this->success(); | ||
279 | + } else { | ||
280 | + $this->error(__('No rows were updated')); | ||
281 | + } | ||
282 | + } | ||
283 | + $this->error(__('Parameter %s can not be empty', '')); | ||
284 | + } | ||
285 | + $this->view->assign("row", $row); | ||
286 | + return $this->view->fetch(); | ||
287 | + } | ||
288 | + | ||
289 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | +use app\api\controller\v1\WxXcxQrcode; | ||
8 | +use think\Exception; | ||
9 | +use think\exception\PDOException; | ||
10 | +use think\exception\ValidateException; | ||
11 | + | ||
12 | +/** | ||
13 | + * 企业管理 | ||
14 | + * | ||
15 | + * @icon fa fa-circle-o | ||
16 | + */ | ||
17 | +class Agentlist extends Backend | ||
18 | +{ | ||
19 | + protected $noNeedRight = ['index']; | ||
20 | + /** | ||
21 | + * Agentlist模型对象 | ||
22 | + * @var \app\admin\model\agent\Agentlist | ||
23 | + */ | ||
24 | + protected $model = null; | ||
25 | + protected $dataLimit = 'auth'; //默认基类中为false,表示不启用,可额外使用auth和personal两个值 | ||
26 | + protected $dataLimitField = 'admin_id'; //数据关联字段,当前控制器对应的模型表中必须存在该字段 | ||
27 | + protected $isSup = 0; | ||
28 | + | ||
29 | + public function _initialize() | ||
30 | + { | ||
31 | + parent::_initialize(); | ||
32 | + $this->model = new \app\admin\model\agent\Agentlist; | ||
33 | + $this->view->assign("agentStuList", $this->model->getAgentStuList()); | ||
34 | + $this->view->assign("payStuList", $this->model->getPayStuList()); | ||
35 | + //判断是否是超级管理员 | ||
36 | + if (in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
37 | + $this->isSup = 1; | ||
38 | + } else { | ||
39 | + $this->isSup = 0; | ||
40 | + } | ||
41 | + $this->view->assign("isSup", $this->isSup); | ||
42 | + } | ||
43 | + | ||
44 | + public function import() | ||
45 | + { | ||
46 | + parent::import(); | ||
47 | + } | ||
48 | + | ||
49 | + | ||
50 | + /** | ||
51 | + * 查看 | ||
52 | + */ | ||
53 | + public function index() | ||
54 | + { | ||
55 | + //当前是否为关联查询 | ||
56 | + $this->relationSearch = true; | ||
57 | + //设置过滤方法 | ||
58 | + $this->request->filter(['strip_tags', 'trim']); | ||
59 | + if ($this->request->isAjax()) { | ||
60 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
61 | + if ($this->request->request('keyField')) { | ||
62 | + return $this->selectpage(); | ||
63 | + } | ||
64 | + list($where, $sort, $order, $offset, $limit) = $this->buildparamsAdm(); | ||
65 | + | ||
66 | + $list = $this->model | ||
67 | + ->with(['user', 'agentcategory']) | ||
68 | + ->where($where) | ||
69 | + ->order($sort, $order) | ||
70 | + ->paginate($limit); | ||
71 | + | ||
72 | + foreach ($list as $row) { | ||
73 | + $row->visible(['id', 'user_id', 'agent_name', 'head_image', 'createtime', 'fr_name', 'fr_mobile', 'fzr_name', 'fzr_mobile', 'address', 'latitude', 'longitude', 'add_day', 'yeji', 'year_pays', 'pay_amount', 'card_image', 'cert_images', 'cert_desc', 'agent_content', 'agent_stu', 'start_pay_time', 'end_pay_time', 'pay_stu', 'credit']); | ||
74 | + $row->visible(['user', 'agentcategory']); | ||
75 | + $row->getRelation('user')->visible(['username', 'nickname']); | ||
76 | + $row->getRelation('agentcategory')->visible(['catname']); | ||
77 | + } | ||
78 | + | ||
79 | + $result = array("total" => $list->total(), "rows" => $list->items()); | ||
80 | + | ||
81 | + return json($result); | ||
82 | + } | ||
83 | + return $this->view->fetch(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * 添加 | ||
88 | + */ | ||
89 | + public function add() | ||
90 | + { | ||
91 | + if ($this->request->isPost()) { | ||
92 | + $params = $this->request->post("row/a"); | ||
93 | + if ($params) { | ||
94 | + $params = $this->preExcludeFields($params); | ||
95 | + | ||
96 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
97 | + $params[$this->dataLimitField] = $this->auth->id; | ||
98 | + } | ||
99 | + $result = false; | ||
100 | + | ||
101 | + Db::startTrans(); | ||
102 | + try { | ||
103 | + //是否采用模型验证 | ||
104 | + if ($this->modelValidate) { | ||
105 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
106 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
107 | + $this->model->validateFailException(true)->validate($validate); | ||
108 | + } | ||
109 | + $result = $this->model->allowField(true)->save($params); | ||
110 | + | ||
111 | + | ||
112 | + Db::commit(); | ||
113 | + } catch (ValidateException $e) { | ||
114 | + Db::rollback(); | ||
115 | + $this->error($e->getMessage()); | ||
116 | + } catch (PDOException $e) { | ||
117 | + Db::rollback(); | ||
118 | + $this->error($e->getMessage()); | ||
119 | + } catch (Exception $e) { | ||
120 | + Db::rollback(); | ||
121 | + $this->error($e->getMessage()); | ||
122 | + } | ||
123 | + if ($result !== false) { | ||
124 | + if ($params['agent_stu'] == "1") { | ||
125 | + //审核通过;生成小程序二维码 | ||
126 | + $qrcode_api = new WxXcxQrcode(); | ||
127 | + $path = '/pages/home/company/detail?id=' . $this->model->id; | ||
128 | + $qrcode = $qrcode_api->qrcode($this->model->id, $path, true); | ||
129 | + if (!empty($qrcode)) { | ||
130 | + Db::name("agent_list")->where("id", $this->model->id)->update(["qrcode" => $qrcode, 'updatetime' => time()]); | ||
131 | + } | ||
132 | + } | ||
133 | + $this->success(); | ||
134 | + } else { | ||
135 | + $this->error(__('No rows were inserted')); | ||
136 | + } | ||
137 | + } | ||
138 | + $this->error(__('Parameter %s can not be empty', '')); | ||
139 | + } | ||
140 | + return $this->view->fetch(); | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * 编辑 | ||
145 | + */ | ||
146 | + public function edit($ids = null) | ||
147 | + { | ||
148 | + $row = $this->model->get($ids); | ||
149 | + if (!$row) { | ||
150 | + $this->error(__('No Results were found')); | ||
151 | + } | ||
152 | + $adminIds = $this->getDataLimitAdminIds(); | ||
153 | + /*if (is_array($adminIds)) { | ||
154 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
155 | + $this->error(__('You have no permission')); | ||
156 | + } | ||
157 | + }*/ | ||
158 | + if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
159 | + if (is_array($adminIds)) { | ||
160 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
161 | + $this->error(__('You have no permission')); | ||
162 | + } | ||
163 | + } | ||
164 | + } | ||
165 | + if ($this->request->isPost()) { | ||
166 | + $params = $this->request->post("row/a"); | ||
167 | + if ($params) { | ||
168 | + $params = $this->preExcludeFields($params); | ||
169 | + if ($this->isSup == 0) { | ||
170 | + $params['agent_stu'] = 0; | ||
171 | + } | ||
172 | + $result = false; | ||
173 | + Db::startTrans(); | ||
174 | + try { | ||
175 | + //是否采用模型验证 | ||
176 | + if ($this->modelValidate) { | ||
177 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
178 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
179 | + $row->validateFailException(true)->validate($validate); | ||
180 | + } | ||
181 | + if ($params['agent_stu'] == "1") { | ||
182 | + //审核通过;生成小程序二维码 | ||
183 | + $qrcode_api = new WxXcxQrcode(); | ||
184 | + $path = '/pages/home/company/detail?id=' . $row->id; | ||
185 | + $params['qrcode'] = $qrcode_api->qrcode($row->id, $path, true); | ||
186 | + | ||
187 | + //用法人手机号创建管理员和角色组 | ||
188 | + $rr = add_group_and_admin($params['fr_mobile'], $params['agent_name']); | ||
189 | + if ($rr['back_falg'] == true) { | ||
190 | + //更新admin_id | ||
191 | + $params['admin_id'] = $rr['uid']; | ||
192 | + } | ||
193 | + | ||
194 | + } | ||
195 | + $result = $row->allowField(true)->save($params); | ||
196 | + Db::commit(); | ||
197 | + } catch (ValidateException $e) { | ||
198 | + Db::rollback(); | ||
199 | + $this->error($e->getMessage()); | ||
200 | + } catch (PDOException $e) { | ||
201 | + Db::rollback(); | ||
202 | + $this->error($e->getMessage()); | ||
203 | + } catch (Exception $e) { | ||
204 | + Db::rollback(); | ||
205 | + $this->error($e->getMessage()); | ||
206 | + } | ||
207 | + if ($result !== false) { | ||
208 | + //推送公众号消息给入驻人 | ||
209 | + if ($params['agent_stu'] == '1' || $params['agent_stu'] == '2') { | ||
210 | + if ($params['agent_stu'] == '1') { | ||
211 | + $desctit = "企业入驻审核通过"; | ||
212 | + $remark = '审核通过'; | ||
213 | + } | ||
214 | + if ($params['agent_stu'] == '2') { | ||
215 | + $desctit = "企业入驻审核不通过"; | ||
216 | + $remark = '不通过原因:' . $params['remark']; | ||
217 | + } | ||
218 | + //获得入驻人openid | ||
219 | + $openid = Db::name('user') | ||
220 | + ->alias('u') | ||
221 | + ->join('wct_user wct', 'u.unionid=wct.unionid') | ||
222 | + ->where(['u.id' => $params['user_id']]) | ||
223 | + ->field('wct.id,wct.wx_openid') | ||
224 | + ->find(); | ||
225 | + if (!empty($openid['wx_openid'])) { | ||
226 | + //推送公众号模板信息给企业管理人 | ||
227 | + $this->senWxmsgToAgentUser($desctit, $openid['wx_openid'], $remark); | ||
228 | + } | ||
229 | + } | ||
230 | + | ||
231 | + $this->success(); | ||
232 | + } else { | ||
233 | + $this->error(__('No rows were updated')); | ||
234 | + } | ||
235 | + } | ||
236 | + $this->error(__('Parameter %s can not be empty', '')); | ||
237 | + } | ||
238 | + $this->view->assign("row", $row); | ||
239 | + return $this->view->fetch(); | ||
240 | + } | ||
241 | + | ||
242 | + /*** | ||
243 | + * 公众号推送审核信息给经纪人 | ||
244 | + */ | ||
245 | + private function senWxmsgToAgentUser($titdesc, $wxopenid, $remark) | ||
246 | + { | ||
247 | + $sendInfo = array( | ||
248 | + 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"), | ||
249 | + 'keyword1' => array('value' => urlencode(date('Y-m-d H:i:s', time())), 'color' => '#173177'), | ||
250 | + 'keyword2' => array('value' => urlencode('企业入驻'), 'color' => '#173177'), | ||
251 | + 'remark' => array('value' => urlencode($remark), 'color' => '#173177'), | ||
252 | + ); | ||
253 | + if ($wxopenid) { | ||
254 | + $config = get_addon_config('wechat'); | ||
255 | + $tourl = 'https://fdc.xp.yn.cn/h5/'; | ||
256 | + $ywt_appid = 'wx9f73637c6b8f2c47'; | ||
257 | + $pagepath = 'pages/home/index'; | ||
258 | + $res = sendAstuWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
259 | + //file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
260 | + } | ||
261 | + } | ||
262 | + | ||
263 | + /** | ||
264 | + * 删除 | ||
265 | + */ | ||
266 | + public function del($ids = "") | ||
267 | + { | ||
268 | + if (!$this->request->isPost()) { | ||
269 | + $this->error(__("Invalid parameters")); | ||
270 | + } | ||
271 | + $ids = $ids ? $ids : $this->request->post("ids"); | ||
272 | + if ($ids) { | ||
273 | + $pk = $this->model->getPk(); | ||
274 | + $adminIds = $this->getDataLimitAdminIds(); | ||
275 | + if (is_array($adminIds)) { | ||
276 | + $this->model->where($this->dataLimitField, 'in', [1, 2, 26, 32, 37]); | ||
277 | + } | ||
278 | + $list = Db::name('agent_list')->where($pk, 'in', $ids)->select(); | ||
279 | + | ||
280 | + $count = 0; | ||
281 | + Db::startTrans(); | ||
282 | + try { | ||
283 | + foreach ($list as $k => $v) { | ||
284 | + //获得企业下门店信息 | ||
285 | + $shoplist = Db::name('agent_shop') | ||
286 | + ->where(['agent_list_id' => $v['id']]) | ||
287 | + ->select(); | ||
288 | + $list[$k]['shop_list'] = $shoplist; | ||
289 | + //先生成数据日志 | ||
290 | + $logs['admin_id'] = $this->auth->id; | ||
291 | + $logs['type'] = 'del'; | ||
292 | + $logs['tablename'] = 'agent_list'; | ||
293 | + $logs['content'] = json_encode($list[$k], JSON_UNESCAPED_UNICODE); | ||
294 | + $logs['createtime'] = time(); | ||
295 | + Db::name('agent_admin_dologs')->insertGetId($logs); | ||
296 | + //禁用企业后台管理员账号 | ||
297 | + if ($v['admin_id'] > 2 && $v['admin_id'] != $this->auth->id) { | ||
298 | + $adminadm['status'] = 'hidden'; | ||
299 | + $adminadm['updatetime'] = time(); | ||
300 | + Db::name('admin') | ||
301 | + ->where(['id' => $v['admin_id']]) | ||
302 | + ->update($adminadm); | ||
303 | + } | ||
304 | + if ($shoplist) { | ||
305 | + //删除企业的门店信息 | ||
306 | + Db::name('agent_shop') | ||
307 | + ->where(['agent_list_id' => $v['id']]) | ||
308 | + ->delete(); | ||
309 | + } | ||
310 | + //删除企业信息 | ||
311 | + | ||
312 | + $count = Db::name('agent_list')->where(['id' => $v['id']])->delete(); | ||
313 | + } | ||
314 | + Db::commit(); | ||
315 | + } catch (PDOException $e) { | ||
316 | + Db::rollback(); | ||
317 | + $this->error($e->getMessage()); | ||
318 | + } catch (Exception $e) { | ||
319 | + Db::rollback(); | ||
320 | + $this->error($e->getMessage()); | ||
321 | + } | ||
322 | + if ($count) { | ||
323 | + $this->success(); | ||
324 | + } else { | ||
325 | + $this->error(__('No rows were deleted')); | ||
326 | + } | ||
327 | + } | ||
328 | + $this->error(__('Parameter %s can not be empty', 'ids')); | ||
329 | + } | ||
330 | + | ||
331 | + | ||
332 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | +use app\api\controller\v1\WxXcxQrcode; | ||
8 | + | ||
9 | +/** | ||
10 | + * 企业门店管理 | ||
11 | + * | ||
12 | + * @icon fa fa-circle-o | ||
13 | + */ | ||
14 | +class Agentshop extends Backend | ||
15 | +{ | ||
16 | + protected $noNeedRight = ['index']; | ||
17 | + /** | ||
18 | + * Agentshop模型对象 | ||
19 | + * @var \app\admin\model\agent\Agentshop | ||
20 | + */ | ||
21 | + protected $model = null; | ||
22 | + protected $dataLimit = 'auth'; | ||
23 | + protected $dataLimitField = 'admin_id'; | ||
24 | + | ||
25 | + public function _initialize() | ||
26 | + { | ||
27 | + parent::_initialize(); | ||
28 | + $this->model = new \app\admin\model\agent\Agentshop; | ||
29 | + $this->view->assign("agentStuList", $this->model->getAgentStuList()); | ||
30 | + $this->view->assign("payStuList", $this->model->getPayStuList()); | ||
31 | + //选择的企业id | ||
32 | + $agentListIds = $this->request->param('ids', 0); | ||
33 | + $ginfo = Db::name('agent_list') | ||
34 | + ->where(['id' => $agentListIds]) | ||
35 | + ->find(); | ||
36 | + $this->view->assign("ginfo", $ginfo); | ||
37 | + //判断是否是超级管理员 | ||
38 | + if (in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
39 | + $isSup = 1; | ||
40 | + } else { | ||
41 | + $isSup = 0; | ||
42 | + } | ||
43 | + $this->view->assign("isSup", $isSup); | ||
44 | + } | ||
45 | + | ||
46 | + public function import() | ||
47 | + { | ||
48 | + parent::import(); | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * 查看 | ||
53 | + */ | ||
54 | + public function index() | ||
55 | + { | ||
56 | + //当前是否为关联查询 | ||
57 | + $this->relationSearch = true; | ||
58 | + //设置过滤方法 | ||
59 | + $this->request->filter(['strip_tags', 'trim']); | ||
60 | + if ($this->request->isAjax()) { | ||
61 | + $ids = $this->request->param('ids'); | ||
62 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
63 | + if ($this->request->request('keyField')) { | ||
64 | + return $this->selectpage(); | ||
65 | + } | ||
66 | + list($where, $sort, $order, $offset, $limit) = $this->buildparamsAdm(); | ||
67 | + | ||
68 | + $list = $this->model | ||
69 | + ->with(['agentlist']) | ||
70 | + ->where(['agent_list_id' => $ids]) | ||
71 | + ->where($where) | ||
72 | + ->order($sort, $order) | ||
73 | + ->paginate($limit); | ||
74 | + | ||
75 | + foreach ($list as $row) { | ||
76 | + $row->visible(['id', 'agent_list_id', 'shop_name', 'head_image', 'createtime', 'updatetime', 'shop_fr_name', 'shop_fr_mobile', 'shop_fzr_name', 'shop_fzr_mobile', 'address', 'latitude', 'longitude', 'add_day', 'card_image', 'cert_images', 'cert_desc', 'agent_content', 'agent_stu', 'credit']); | ||
77 | + $row->visible(['agentlist']); | ||
78 | + $row->getRelation('agentlist')->visible(['agent_name']); | ||
79 | + } | ||
80 | + | ||
81 | + $result = array("total" => $list->total(), "rows" => $list->items()); | ||
82 | + | ||
83 | + return json($result); | ||
84 | + } | ||
85 | + return $this->view->fetch(); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * 添加 | ||
90 | + */ | ||
91 | + public function add() | ||
92 | + { | ||
93 | + if ($this->request->isPost()) { | ||
94 | + $params = $this->request->post("row/a"); | ||
95 | + if ($params) { | ||
96 | + $params = $this->preExcludeFields($params); | ||
97 | + $params['admin_id'] = agent_list_admin_id($params['agent_list_id']); | ||
98 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
99 | + $params[$this->dataLimitField] = $this->auth->id; | ||
100 | + } | ||
101 | + $result = false; | ||
102 | + | ||
103 | + Db::startTrans(); | ||
104 | + try { | ||
105 | + //是否采用模型验证 | ||
106 | + if ($this->modelValidate) { | ||
107 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
108 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
109 | + $this->model->validateFailException(true)->validate($validate); | ||
110 | + } | ||
111 | + $result = $this->model->allowField(true)->save($params); | ||
112 | + | ||
113 | + | ||
114 | + Db::commit(); | ||
115 | + } catch (ValidateException $e) { | ||
116 | + Db::rollback(); | ||
117 | + $this->error($e->getMessage()); | ||
118 | + } catch (PDOException $e) { | ||
119 | + Db::rollback(); | ||
120 | + $this->error($e->getMessage()); | ||
121 | + } catch (Exception $e) { | ||
122 | + Db::rollback(); | ||
123 | + $this->error($e->getMessage()); | ||
124 | + } | ||
125 | + if ($result !== false) { | ||
126 | + if ($params['agent_stu'] == "1") { | ||
127 | + //审核通过;生成小程序二维码 | ||
128 | + $qrcode_api = new WxXcxQrcode(); | ||
129 | + $path = '/pages/home/company/storeDetail?id=' . $this->model->id; | ||
130 | + $qrcode = $qrcode_api->qrcode($this->model->id, $path, true); | ||
131 | + if (!empty($qrcode)) { | ||
132 | + Db::name("agent_shop")->where("id", $this->model->id)->update(["qrcode" => $qrcode, 'updatetime' => time()]); | ||
133 | + } | ||
134 | + } | ||
135 | + $this->success(); | ||
136 | + } else { | ||
137 | + $this->error(__('No rows were inserted')); | ||
138 | + } | ||
139 | + } | ||
140 | + $this->error(__('Parameter %s can not be empty', '')); | ||
141 | + } | ||
142 | + return $this->view->fetch(); | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * 编辑 | ||
147 | + */ | ||
148 | + public function edit($ids = null) | ||
149 | + { | ||
150 | + $row = $this->model->get($ids); | ||
151 | + if (!$row) { | ||
152 | + $this->error(__('No Results were found')); | ||
153 | + } | ||
154 | + $adminIds = $this->getDataLimitAdminIds(); | ||
155 | + /*if (is_array($adminIds)) { | ||
156 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
157 | + $this->error(__('You have no permission')); | ||
158 | + } | ||
159 | + }*/ | ||
160 | + if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
161 | + if (is_array($adminIds)) { | ||
162 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
163 | + $this->error(__('You have no permission')); | ||
164 | + } | ||
165 | + } | ||
166 | + } | ||
167 | + if ($this->request->isPost()) { | ||
168 | + $params = $this->request->post("row/a"); | ||
169 | + if ($params) { | ||
170 | + $params = $this->preExcludeFields($params); | ||
171 | + $params['admin_id'] = agent_list_admin_id($params['agent_list_id']); | ||
172 | + $result = false; | ||
173 | + Db::startTrans(); | ||
174 | + try { | ||
175 | + //是否采用模型验证 | ||
176 | + if ($this->modelValidate) { | ||
177 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
178 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
179 | + $row->validateFailException(true)->validate($validate); | ||
180 | + } | ||
181 | + if ($params['agent_stu'] == "1") { | ||
182 | + //审核通过;生成小程序二维码 | ||
183 | + $qrcode_api = new WxXcxQrcode(); | ||
184 | + $path = '/pages/home/company/storeDetail?id=' . $row->id; | ||
185 | + $params['qrcode'] = $qrcode_api->qrcode($row->id, $path, true); | ||
186 | + } | ||
187 | + $result = $row->allowField(true)->save($params); | ||
188 | + Db::commit(); | ||
189 | + } catch (ValidateException $e) { | ||
190 | + Db::rollback(); | ||
191 | + $this->error($e->getMessage()); | ||
192 | + } catch (PDOException $e) { | ||
193 | + Db::rollback(); | ||
194 | + $this->error($e->getMessage()); | ||
195 | + } catch (Exception $e) { | ||
196 | + Db::rollback(); | ||
197 | + $this->error($e->getMessage()); | ||
198 | + } | ||
199 | + if ($result !== false) { | ||
200 | + $this->success(); | ||
201 | + } else { | ||
202 | + $this->error(__('No rows were updated')); | ||
203 | + } | ||
204 | + } | ||
205 | + $this->error(__('Parameter %s can not be empty', '')); | ||
206 | + } | ||
207 | + $this->view->assign("row", $row); | ||
208 | + return $this->view->fetch(); | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
212 | + * 删除 | ||
213 | + */ | ||
214 | + public function del($ids = "") | ||
215 | + { | ||
216 | + if (!$this->request->isPost()) { | ||
217 | + $this->error(__("Invalid parameters")); | ||
218 | + } | ||
219 | + $ids = $ids ? $ids : $this->request->post("ids"); | ||
220 | + if ($ids) { | ||
221 | + $pk = $this->model->getPk(); | ||
222 | + $adminIds = $this->getDataLimitAdminIds(); | ||
223 | + if (is_array($adminIds)) { | ||
224 | + $this->model->where($this->dataLimitField, 'in', [1, 2, 26, 32, 37]); | ||
225 | + } | ||
226 | + $list = $this->model->where($pk, 'in', $ids)->select(); | ||
227 | + | ||
228 | + $count = 0; | ||
229 | + Db::startTrans(); | ||
230 | + try { | ||
231 | + foreach ($list as $k => $v) { | ||
232 | + $count += $v->delete(); | ||
233 | + } | ||
234 | + Db::commit(); | ||
235 | + } catch (PDOException $e) { | ||
236 | + Db::rollback(); | ||
237 | + $this->error($e->getMessage()); | ||
238 | + } catch (Exception $e) { | ||
239 | + Db::rollback(); | ||
240 | + $this->error($e->getMessage()); | ||
241 | + } | ||
242 | + if ($count) { | ||
243 | + $this->success(); | ||
244 | + } else { | ||
245 | + $this->error(__('No rows were deleted')); | ||
246 | + } | ||
247 | + } | ||
248 | + $this->error(__('Parameter %s can not be empty', 'ids')); | ||
249 | + } | ||
250 | + | ||
251 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | +use app\api\controller\v1\WxXcxQrcode; | ||
8 | +use PhpOffice\PhpSpreadsheet\Helper\Sample; | ||
9 | +use PhpOffice\PhpSpreadsheet\IOFactory; | ||
10 | +use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
11 | +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; | ||
12 | +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; | ||
13 | +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; | ||
14 | +use PhpOffice\PhpSpreadsheet\Cell\DataType; | ||
15 | +use PhpOffice\PhpSpreadsheet\Style\Fill; | ||
16 | +use PhpOffice\PhpSpreadsheet\Style\Color; | ||
17 | +use PhpOffice\PhpSpreadsheet\Style\Alignment; | ||
18 | +use PhpOffice\PhpSpreadsheet\Style\Border; | ||
19 | +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; | ||
20 | + | ||
21 | +/** | ||
22 | + * 经纪人管理 | ||
23 | + * | ||
24 | + * @icon fa fa-circle-o | ||
25 | + */ | ||
26 | +class Agentusers extends Backend | ||
27 | +{ | ||
28 | + | ||
29 | + /** | ||
30 | + * Agentusers模型对象 | ||
31 | + * @var \app\admin\model\agent\Agentusers | ||
32 | + */ | ||
33 | + protected $model = null; | ||
34 | + protected $dataLimit = 'auth'; | ||
35 | + protected $dataLimitField = 'admin_id'; | ||
36 | + protected $relationSearch = true; | ||
37 | + protected $searchFields = 'id,jjr_name,agentlist,jjr_mobile'; | ||
38 | + protected $selectpageFields = "id,jjr_name,agentlist,jjr_mobile"; | ||
39 | + protected $issupAdm; | ||
40 | + | ||
41 | + public function _initialize() | ||
42 | + { | ||
43 | + parent::_initialize(); | ||
44 | + $this->model = new \app\admin\model\agent\Agentusers; | ||
45 | + $this->view->assign("jjrTypeList", $this->model->getJjrTypeList()); | ||
46 | + $this->view->assign("jjrAgentStuList", $this->model->getJjrAgentStuList()); | ||
47 | + $this->view->assign("jjrPayStuList", $this->model->getJjrPayStuList()); | ||
48 | + $this->view->assign("getIndustry", $this->model->getIndustry()); | ||
49 | + //判断是否是超级管理员 | ||
50 | + if (in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
51 | + $isSup = 1; | ||
52 | + } else { | ||
53 | + $isSup = 0; | ||
54 | + } | ||
55 | + $this->issupAdm = $isSup; | ||
56 | + $this->view->assign("isSup", $isSup); | ||
57 | + } | ||
58 | + | ||
59 | + | ||
60 | + /** | ||
61 | + * 查看 | ||
62 | + */ | ||
63 | + public function index() | ||
64 | + { | ||
65 | + //当前是否为关联查询 | ||
66 | + $this->relationSearch = true; | ||
67 | + //设置过滤方法 | ||
68 | + $this->request->filter(['strip_tags', 'trim']); | ||
69 | + if ($this->request->isAjax()) { | ||
70 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
71 | + if ($this->request->request('keyField')) { | ||
72 | + return $this->selectpage(); | ||
73 | + } | ||
74 | + list($where, $sort, $order, $offset, $limit) = $this->buildparamsAdm(); | ||
75 | + | ||
76 | + if ($this->issupAdm == 1) { | ||
77 | + $list = $this->model | ||
78 | + ->with(['agentusercat', 'agentusereducat', 'agentlist', 'user', 'agentshoplist']) | ||
79 | + ->where($where) | ||
80 | + ->order($sort, $order) | ||
81 | + ->paginate($limit); | ||
82 | + } else { | ||
83 | + $list = $this->model | ||
84 | + ->with(['agentusercat', 'agentusereducat', 'agentlist', 'user', 'agentshoplist']) | ||
85 | + ->where($where) | ||
86 | + ->order($sort, $order) | ||
87 | + ->paginate($limit); | ||
88 | + } | ||
89 | + | ||
90 | + foreach ($list as $row) { | ||
91 | + $row->visible(['id', 'user_id', 'jjr_sex', 'agent_shop_id', 'agent_list_id', 'jjr_type', 'user_cat_id', 'user_educat_id', 'jjr_name', 'jjr_image', 'createtime', 'updatetime', 'jjr_mobile', 'home_address', 'now_address', 'idcard', 'idcard_images', 'jjr_content', 'jjr_agent_stu', 'jjr_start_pay_time', 'jjr_end_pay_time', 'jjr_pay_stu', 'credit', 'addstep', 'jjr_type_uptime', 'is_stu_ok', 'is_test_ok', 'userno','industry']); | ||
92 | + $row->visible(['agentusercat']); | ||
93 | + $row->getRelation('agentusercat')->visible(['catname']); | ||
94 | + $row->visible(['agentusereducat']); | ||
95 | + $row->getRelation('agentusereducat')->visible(['educat_name']); | ||
96 | + $row->visible(['agentlist']); | ||
97 | + $row->getRelation('agentlist')->visible(['agent_name']); | ||
98 | + $row->visible(['agentshoplist']); | ||
99 | + $row->getRelation('agentshoplist')->visible(['shop_name']); | ||
100 | + $row->visible(['user']); | ||
101 | + $row->getRelation('user')->visible(['username', 'nickname']); | ||
102 | + } | ||
103 | + $rows = $list->items(); | ||
104 | + $getIndustry = $this->model->getIndustry(); | ||
105 | + foreach ($rows as $kk => $vv) { | ||
106 | + //身份证处理 | ||
107 | + $rows[$kk]['idcard'] = tyssl_decode($vv['idcard']); | ||
108 | + //判断入驻进度 | ||
109 | + if ($vv['jjr_pay_stu'] == '0' && $vv['is_stu_ok'] == '0' && $vv['is_test_ok'] == '0') { | ||
110 | + $rows[$kk]['addstep'] = '未支付年费'; | ||
111 | + } | ||
112 | + if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '0' && $vv['is_test_ok'] == '0') { | ||
113 | + $rows[$kk]['addstep'] = '已支付年费'; | ||
114 | + } | ||
115 | + /* | ||
116 | + if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '1' && $vv['is_test_ok'] == '0') { | ||
117 | + $rows[$kk]['addstep'] = '培训完成,考试中'; | ||
118 | + } | ||
119 | + if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '1' && $vv['is_test_ok'] == '1' && $vv['jjr_type_uptime'] == 0) { | ||
120 | + $rows[$kk]['addstep'] = '考试完成,未选择身份'; | ||
121 | + } | ||
122 | + if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '1' && $vv['is_test_ok'] == '1' && $vv['jjr_type_uptime'] > 0) { | ||
123 | + $rows[$kk]['addstep'] = '已完成'; | ||
124 | + } | ||
125 | + */ | ||
126 | + //判断入驻考试是否完成 | ||
127 | + $testok = getUserGradOk($vv['user_id']); | ||
128 | + if ($testok == 1) { | ||
129 | + $rows[$kk]['userno'] = '未经考试合格暂无工号'; | ||
130 | + } | ||
131 | + //从事行业处理 | ||
132 | + $rows[$kk]['industry'] = !empty($vv['industry'])?$getIndustry[$vv['industry']]:''; | ||
133 | + | ||
134 | + } | ||
135 | + | ||
136 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
137 | + | ||
138 | + return json($result); | ||
139 | + } | ||
140 | + return $this->view->fetch(); | ||
141 | + } | ||
142 | + | ||
143 | + | ||
144 | + /** | ||
145 | + * 添加 | ||
146 | + */ | ||
147 | + public function add() | ||
148 | + { | ||
149 | + if ($this->request->isPost()) { | ||
150 | + $params = $this->request->post("row/a"); | ||
151 | + if ($params) { | ||
152 | + $params = $this->preExcludeFields($params); | ||
153 | + $params['idcard'] = tyssl_encode($params['idcard']); | ||
154 | + //经纪人身份 | ||
155 | + $params['jjr_type_uptime'] = time(); | ||
156 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
157 | + $params[$this->dataLimitField] = $this->auth->id; | ||
158 | + } | ||
159 | + | ||
160 | + $result = false; | ||
161 | + Db::startTrans(); | ||
162 | + try { | ||
163 | + //是否采用模型验证 | ||
164 | + if ($this->modelValidate) { | ||
165 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
166 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
167 | + $this->model->validateFailException(true)->validate($validate); | ||
168 | + } | ||
169 | + $result = $this->model->allowField(true)->save($params); | ||
170 | + Db::commit(); | ||
171 | + } catch (ValidateException $e) { | ||
172 | + Db::rollback(); | ||
173 | + $this->error($e->getMessage()); | ||
174 | + } catch (PDOException $e) { | ||
175 | + Db::rollback(); | ||
176 | + $this->error($e->getMessage()); | ||
177 | + } catch (Exception $e) { | ||
178 | + Db::rollback(); | ||
179 | + $this->error($e->getMessage()); | ||
180 | + } | ||
181 | + if ($result !== false) { | ||
182 | + //如果选择了企业,添加经纪人归属 | ||
183 | + $userup['admin_id'] = 2; | ||
184 | + if ($params['jjr_type'] == '1') { | ||
185 | + $userup['admin_id'] = agent_list_admin_id($params['agent_list_id']); | ||
186 | + } | ||
187 | + | ||
188 | + if ($params['jjr_agent_stu'] == "1") { | ||
189 | + //审核通过;生成小程序二维码 | ||
190 | + $qrcode_api = new WxXcxQrcode(); | ||
191 | + $path = '/pages/home/broker/broker?id=' . $this->model->id; | ||
192 | + $qrcode = $qrcode_api->qrcode($this->model->id, $path, true); | ||
193 | + if (!empty($qrcode)) { | ||
194 | + $userup['qrcode'] = $qrcode; | ||
195 | + } | ||
196 | + } | ||
197 | + $userup['updatetime'] = time(); | ||
198 | + Db::name("agent_users") | ||
199 | + ->where("id", $this->model->id) | ||
200 | + ->update($userup); | ||
201 | + $this->success(); | ||
202 | + } else { | ||
203 | + $this->error(__('No rows were inserted')); | ||
204 | + } | ||
205 | + } | ||
206 | + $this->error(__('Parameter %s can not be empty', '')); | ||
207 | + } | ||
208 | + return $this->view->fetch(); | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
212 | + * 编辑 | ||
213 | + */ | ||
214 | + public function edit($ids = null) | ||
215 | + { | ||
216 | + $row = $this->model->get($ids); | ||
217 | + //处理身份证 | ||
218 | + $row['idcard'] = tyssl_decode($row['idcard']); | ||
219 | + if (!$row) { | ||
220 | + $this->error(__('No Results were found')); | ||
221 | + } | ||
222 | + $adminIds = $this->getDataLimitAdminIds(); | ||
223 | + | ||
224 | + /* | ||
225 | + if (is_array($adminIds)) { | ||
226 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
227 | + $this->error(__('You have no permission')); | ||
228 | + } | ||
229 | + }*/ | ||
230 | + if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
231 | + if (is_array($adminIds)) { | ||
232 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
233 | + $this->error(__('You have no permission')); | ||
234 | + } | ||
235 | + } | ||
236 | + } | ||
237 | + if ($this->request->isPost()) { | ||
238 | + $params = $this->request->post("row/a"); | ||
239 | + if ($params) { | ||
240 | + $params = $this->preExcludeFields($params); | ||
241 | + $params['idcard'] = tyssl_encode($params['idcard']); | ||
242 | + //处理选择为自由经纪人,清空选择的企业 | ||
243 | + if ($params['jjr_type'] == '0') { | ||
244 | + $params['agent_list_id'] = 0; | ||
245 | + $params['agent_shop_id'] = 0; | ||
246 | + } | ||
247 | + //如果选择了企业,添加经纪人归属 | ||
248 | + if ($params['jjr_type'] == '1') { | ||
249 | + $params['admin_id'] = agent_list_admin_id($params['agent_list_id']); | ||
250 | + } | ||
251 | + //流程改动:上传职业证书的用户审核通过就不需要进行考试等等流程;直接成为经纪人 20230804 陈程 | ||
252 | + if($params['jjr_agent_stu'] == '1' && !empty($params['vocational_certificate'])){ | ||
253 | + $time = time(); | ||
254 | + $params['is_test_time'] = $time; // 完成考试时间 | ||
255 | + $params['is_test_ok'] = '1'; //完成入驻考试,0否,1是 | ||
256 | + $params['is_stu_ok'] = '1';//完成培训考试,0否,1是 | ||
257 | + $parms['is_stu_time']= $time;//完成培训时间 | ||
258 | + $params['jjr_type_uptime'] = $time; // 经济人信息更新 表示绑定为经济人了 | ||
259 | + } | ||
260 | + $result = false; | ||
261 | + Db::startTrans(); | ||
262 | + try { | ||
263 | + //是否采用模型验证 | ||
264 | + if ($this->modelValidate) { | ||
265 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
266 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
267 | + $row->validateFailException(true)->validate($validate); | ||
268 | + } | ||
269 | + if ($params['jjr_agent_stu'] == "1") { | ||
270 | + //审核通过;生成小程序二维码 | ||
271 | + $qrcode_api = new WxXcxQrcode(); | ||
272 | + $path = '/pages/home/broker/broker?id=' . $row->id; | ||
273 | + $params['qrcode'] = $qrcode_api->qrcode($row->id, $path, true); | ||
274 | + } | ||
275 | + $result = $row->allowField(true)->save($params); | ||
276 | + Db::commit(); | ||
277 | + } catch (ValidateException $e) { | ||
278 | + Db::rollback(); | ||
279 | + $this->error($e->getMessage()); | ||
280 | + } catch (PDOException $e) { | ||
281 | + Db::rollback(); | ||
282 | + $this->error($e->getMessage()); | ||
283 | + } catch (Exception $e) { | ||
284 | + Db::rollback(); | ||
285 | + $this->error($e->getMessage()); | ||
286 | + } | ||
287 | + if ($result !== false) { | ||
288 | + //公众号消息推送 | ||
289 | + if ($params['jjr_agent_stu'] == '1' || $params['jjr_agent_stu'] == '2') { | ||
290 | + if ($params['jjr_agent_stu'] == '1') { | ||
291 | + $desctit = "经纪人入驻已审核通过"; | ||
292 | + $remark = '审核通过'; | ||
293 | + } | ||
294 | + if ($params['jjr_agent_stu'] == '2') { | ||
295 | + $desctit = "经纪人入驻审核不通过"; | ||
296 | + $remark = '不通过原因:' . $params['remark']; | ||
297 | + } | ||
298 | + //推送公众号模板信息给经纪人 | ||
299 | + $this->senWxmsgToAgentUser($desctit, $row->id, $remark); | ||
300 | + } | ||
301 | + $this->success(); | ||
302 | + } else { | ||
303 | + $this->error(__('No rows were updated')); | ||
304 | + } | ||
305 | + } | ||
306 | + $this->error(__('Parameter %s can not be empty', '')); | ||
307 | + } | ||
308 | + $this->view->assign("row", $row); | ||
309 | + return $this->view->fetch(); | ||
310 | + } | ||
311 | + | ||
312 | + /*** | ||
313 | + * 公众号推送审核信息给经纪人 | ||
314 | + */ | ||
315 | + private function senWxmsgToAgentUser($titdesc, $agent_users_id, $remark) | ||
316 | + { | ||
317 | + $sendInfo = array( | ||
318 | + 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"), | ||
319 | + 'keyword1' => array('value' => urlencode(date('Y-m-d H:i:s', time())), 'color' => '#173177'), | ||
320 | + 'keyword2' => array('value' => urlencode('经纪人入驻'), 'color' => '#173177'), | ||
321 | + 'remark' => array('value' => urlencode($remark), 'color' => '#173177'), | ||
322 | + ); | ||
323 | + $wxopenid = getAgetWxOpenid($agent_users_id); | ||
324 | + if ($wxopenid) { | ||
325 | + $config = get_addon_config('wechat'); | ||
326 | + $tourl = 'https://fdc.xp.yn.cn/h5/'; | ||
327 | + $ywt_appid = 'wx9f73637c6b8f2c47'; | ||
328 | + $pagepath = 'pages/home/index'; | ||
329 | + $res = sendAstuWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
330 | + //file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
331 | + } | ||
332 | + } | ||
333 | + | ||
334 | + /*** | ||
335 | + * 导出测试 | ||
336 | + */ | ||
337 | + public function pclexport() | ||
338 | + { | ||
339 | + //当前是否为关联查询 | ||
340 | + $this->relationSearch = true; | ||
341 | + //设置过滤方法 | ||
342 | + $this->request->filter(['strip_tags', 'trim']); | ||
343 | + if ($this->request->isPost()) { | ||
344 | + set_time_limit(0); | ||
345 | + ini_set('memory_limit', '2048M'); | ||
346 | + $search = $this->request->post('search'); | ||
347 | + $ids = $this->request->post('ids'); | ||
348 | + //搜索条件 | ||
349 | + $filter = $this->request->post('filter'); | ||
350 | + $op = $this->request->post('op'); | ||
351 | + //导出的字段 | ||
352 | + $columns = $this->request->post('columns'); | ||
353 | + | ||
354 | + | ||
355 | + //查询条件 | ||
356 | + $whereIds = $ids == 'all' ? '1=1' : ['agentusers.id' => ['in', explode(',', $ids)]]; | ||
357 | + $this->request->get(['search' => $search, 'ids' => $ids, 'filter' => $filter, 'op' => $op]); | ||
358 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
359 | + //获得数据列表:全部字段的内容 | ||
360 | + $list = $this->model | ||
361 | + ->with(['agentusercat', 'agentusereducat', 'agentlist', 'user', 'agentshoplist']) | ||
362 | + ->where($where) | ||
363 | + ->where($whereIds) | ||
364 | + ->order($sort, $order) | ||
365 | + ->select(); | ||
366 | + | ||
367 | + foreach ($list as $row) { | ||
368 | + $row->visible(['id', 'user_id', 'jjr_sex', 'agent_shop_id', 'agent_list_id', 'jjr_type', 'user_cat_id', 'user_educat_id', 'jjr_name', 'jjr_image', 'createtime', 'updatetime', 'jjr_mobile', 'home_address', 'now_address', 'idcard', 'idcard_images', 'jjr_content', 'jjr_agent_stu', 'jjr_start_pay_time', 'jjr_end_pay_time', 'jjr_pay_stu', 'credit', 'addstep', 'jjr_type_uptime', 'is_stu_ok', 'is_test_ok', 'userno']); | ||
369 | + $row->visible(['agentusercat']); | ||
370 | + $row->getRelation('agentusercat')->visible(['catname']); | ||
371 | + $row->visible(['agentusereducat']); | ||
372 | + $row->getRelation('agentusereducat')->visible(['educat_name']); | ||
373 | + $row->visible(['agentlist']); | ||
374 | + $row->getRelation('agentlist')->visible(['agent_name']); | ||
375 | + $row->visible(['agentshoplist']); | ||
376 | + $row->getRelation('agentshoplist')->visible(['shop_name']); | ||
377 | + $row->visible(['user']); | ||
378 | + $row->getRelation('user')->visible(['username', 'nickname']); | ||
379 | + } | ||
380 | + //对象处理成数组 | ||
381 | + $list = json_encode($list); | ||
382 | + $list = json_decode($list, true); | ||
383 | + | ||
384 | + // var_dump($list); | ||
385 | + | ||
386 | + } | ||
387 | + } | ||
388 | + | ||
389 | + /** | ||
390 | + * 删除 | ||
391 | + */ | ||
392 | + public function del($ids = "") | ||
393 | + { | ||
394 | + if (!$this->request->isPost()) { | ||
395 | + $this->error(__("Invalid parameters")); | ||
396 | + } | ||
397 | + $ids = $ids ? $ids : $this->request->post("ids"); | ||
398 | + if ($ids) { | ||
399 | + $pk = $this->model->getPk(); | ||
400 | + | ||
401 | + $adminIds = $this->getDataLimitAdminIds(); | ||
402 | + | ||
403 | + /*if (!is_array($adminIds)) { | ||
404 | + $this->model->where($this->dataLimitField, 'in', [1, 2, 26, 32, 37]); | ||
405 | + }*/ | ||
406 | + if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
407 | + $this->error(__("Invalid parameters")); | ||
408 | + } | ||
409 | + $list = $this->model->where($pk, 'in', $ids)->select(); | ||
410 | + | ||
411 | + | ||
412 | + $count = 0; | ||
413 | + Db::startTrans(); | ||
414 | + try { | ||
415 | + foreach ($list as $k => $v) { | ||
416 | + $count += $v->delete(); | ||
417 | + } | ||
418 | + Db::commit(); | ||
419 | + } catch (PDOException $e) { | ||
420 | + Db::rollback(); | ||
421 | + $this->error($e->getMessage()); | ||
422 | + } catch (Exception $e) { | ||
423 | + Db::rollback(); | ||
424 | + $this->error($e->getMessage()); | ||
425 | + } | ||
426 | + if ($count) { | ||
427 | + $this->success(); | ||
428 | + } else { | ||
429 | + $this->error(__('No rows were deleted')); | ||
430 | + } | ||
431 | + } | ||
432 | + $this->error(__('Parameter %s can not be empty', 'ids')); | ||
433 | + } | ||
434 | + | ||
435 | + | ||
436 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 经纪人-从事行业 | ||
9 | + * | ||
10 | + * @icon fa fa-circle-o | ||
11 | + */ | ||
12 | +class Agentusersindustry extends Backend | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * Agentusersindustry模型对象 | ||
17 | + * @var \app\admin\model\agent\Agentusersindustry | ||
18 | + */ | ||
19 | + protected $model = null; | ||
20 | + | ||
21 | + public function _initialize() | ||
22 | + { | ||
23 | + parent::_initialize(); | ||
24 | + $this->model = new \app\admin\model\agent\Agentusersindustry; | ||
25 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
26 | + } | ||
27 | + | ||
28 | + public function import() | ||
29 | + { | ||
30 | + parent::import(); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 | ||
35 | + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 | ||
36 | + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 | ||
37 | + */ | ||
38 | + | ||
39 | + | ||
40 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 用户预约分类管理 | ||
9 | + * | ||
10 | + * @icon fa fa-circle-o | ||
11 | + */ | ||
12 | +class Appointmentcat extends Backend | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * Appointmentcat模型对象 | ||
17 | + * @var \app\admin\model\agent\Appointmentcat | ||
18 | + */ | ||
19 | + protected $model = null; | ||
20 | + | ||
21 | + public function _initialize() | ||
22 | + { | ||
23 | + parent::_initialize(); | ||
24 | + $this->model = new \app\admin\model\agent\Appointmentcat; | ||
25 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
26 | + } | ||
27 | + | ||
28 | + public function import() | ||
29 | + { | ||
30 | + parent::import(); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 | ||
35 | + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 | ||
36 | + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 | ||
37 | + */ | ||
38 | + | ||
39 | + | ||
40 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 用户预约记录 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Appointmentlist extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Appointmentlist模型对象 | ||
18 | + * @var \app\admin\model\agent\Appointmentlist | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Appointmentlist; | ||
26 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * 查看 | ||
31 | + */ | ||
32 | + public function index() | ||
33 | + { | ||
34 | + //当前是否为关联查询 | ||
35 | + $this->relationSearch = true; | ||
36 | + //设置过滤方法 | ||
37 | + $this->request->filter(['strip_tags', 'trim']); | ||
38 | + if ($this->request->isAjax()) { | ||
39 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
40 | + if ($this->request->request('keyField')) { | ||
41 | + return $this->selectpage(); | ||
42 | + } | ||
43 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
44 | + | ||
45 | + $list = $this->model | ||
46 | + ->with(['agentuserappointmentcat', 'user']) | ||
47 | + ->where($where) | ||
48 | + ->order($sort, $order) | ||
49 | + ->paginate($limit); | ||
50 | + | ||
51 | + foreach ($list as $row) { | ||
52 | + | ||
53 | + $row->getRelation('agentuserappointmentcat')->visible(['catname']); | ||
54 | + $row->getRelation('user')->visible(['id', 'username', 'nickname', 'mobile', 'unionid']); | ||
55 | + } | ||
56 | + | ||
57 | + $result = array("total" => $list->total(), "rows" => $list->items()); | ||
58 | + | ||
59 | + return json($result); | ||
60 | + } | ||
61 | + return $this->view->fetch(); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * 编辑 | ||
66 | + */ | ||
67 | + public function edit($ids = null) | ||
68 | + { | ||
69 | + $row = $this->model->get($ids); | ||
70 | + if (!$row) { | ||
71 | + $this->error(__('No Results were found')); | ||
72 | + } | ||
73 | + $adminIds = $this->getDataLimitAdminIds(); | ||
74 | + /*if (is_array($adminIds)) { | ||
75 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
76 | + $this->error(__('You have no permission')); | ||
77 | + } | ||
78 | + }*/ | ||
79 | + if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) { | ||
80 | + if (is_array($adminIds)) { | ||
81 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
82 | + $this->error(__('You have no permission')); | ||
83 | + } | ||
84 | + } | ||
85 | + } | ||
86 | + if ($this->request->isPost()) { | ||
87 | + $params = $this->request->post("row/a"); | ||
88 | + if ($params) { | ||
89 | + $params = $this->preExcludeFields($params); | ||
90 | + $params['asktimes'] = strtotime($params['asktime']); | ||
91 | + | ||
92 | + $result = false; | ||
93 | + Db::startTrans(); | ||
94 | + try { | ||
95 | + //是否采用模型验证 | ||
96 | + if ($this->modelValidate) { | ||
97 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
98 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
99 | + $row->validateFailException(true)->validate($validate); | ||
100 | + } | ||
101 | + | ||
102 | + $result = $row->allowField(true)->save($params); | ||
103 | + Db::commit(); | ||
104 | + } catch (ValidateException $e) { | ||
105 | + Db::rollback(); | ||
106 | + $this->error($e->getMessage()); | ||
107 | + } catch (PDOException $e) { | ||
108 | + Db::rollback(); | ||
109 | + $this->error($e->getMessage()); | ||
110 | + } catch (Exception $e) { | ||
111 | + Db::rollback(); | ||
112 | + $this->error($e->getMessage()); | ||
113 | + } | ||
114 | + if ($result !== false) { | ||
115 | + $this->success(); | ||
116 | + } else { | ||
117 | + $this->error(__('No rows were updated')); | ||
118 | + } | ||
119 | + } | ||
120 | + $this->error(__('Parameter %s can not be empty', '')); | ||
121 | + } | ||
122 | + $this->view->assign("row", $row); | ||
123 | + return $this->view->fetch(); | ||
124 | + } | ||
125 | + | ||
126 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 用户投诉分类管理 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Complaincat extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Complaincat模型对象 | ||
18 | + * @var \app\admin\model\agent\Complaincat | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Complaincat; | ||
26 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
27 | + } | ||
28 | + | ||
29 | + public function import() | ||
30 | + { | ||
31 | + parent::import(); | ||
32 | + } | ||
33 | + | ||
34 | + | ||
35 | + /** | ||
36 | + * 查看 | ||
37 | + */ | ||
38 | + public function index() | ||
39 | + { | ||
40 | + //当前是否为关联查询 | ||
41 | + $this->relationSearch = false; | ||
42 | + //设置过滤方法 | ||
43 | + $this->request->filter(['strip_tags', 'trim']); | ||
44 | + if ($this->request->isAjax()) { | ||
45 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
46 | + if ($this->request->request('keyField')) { | ||
47 | + return $this->selectpage(); | ||
48 | + } | ||
49 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
50 | + | ||
51 | + $list = $this->model | ||
52 | + ->where($where) | ||
53 | + ->order($sort, $order) | ||
54 | + ->paginate($limit); | ||
55 | + | ||
56 | + foreach ($list as $row) { | ||
57 | + $row->visible(['id', 'catname', 'createtime', 'weigh', 'status']); | ||
58 | + | ||
59 | + } | ||
60 | + | ||
61 | + $result = array("total" => $list->total(), "rows" => $list->items()); | ||
62 | + | ||
63 | + return json($result); | ||
64 | + } | ||
65 | + return $this->view->fetch(); | ||
66 | + } | ||
67 | + | ||
68 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 用户投诉记录 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Complainlist extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Complainlist模型对象 | ||
18 | + * @var \app\admin\model\agent\Complainlist | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + protected $dataLimit = 'auth'; | ||
22 | + protected $dataLimitField = 'admin_id'; | ||
23 | + | ||
24 | + public function _initialize() | ||
25 | + { | ||
26 | + parent::_initialize(); | ||
27 | + $this->model = new \app\admin\model\agent\Complainlist; | ||
28 | + $this->view->assign("typeList", $this->model->getTypeList()); | ||
29 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
30 | + //判断是否是超级管理员 | ||
31 | + if (in_array($this->auth->id, [1, 2])) { | ||
32 | + $isSup = 1; | ||
33 | + } else { | ||
34 | + $isSup = 0; | ||
35 | + } | ||
36 | + $this->view->assign("isSup", $isSup); | ||
37 | + } | ||
38 | + | ||
39 | + public function import() | ||
40 | + { | ||
41 | + parent::import(); | ||
42 | + } | ||
43 | + | ||
44 | + | ||
45 | + /** | ||
46 | + * 查看 | ||
47 | + */ | ||
48 | + public function index() | ||
49 | + { | ||
50 | + //当前是否为关联查询 | ||
51 | + $this->relationSearch = true; | ||
52 | + //设置过滤方法 | ||
53 | + $this->request->filter(['strip_tags', 'trim']); | ||
54 | + if ($this->request->isAjax()) { | ||
55 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
56 | + if ($this->request->request('keyField')) { | ||
57 | + return $this->selectpage(); | ||
58 | + } | ||
59 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
60 | + | ||
61 | + $list = $this->model | ||
62 | + ->with(['agentlist', 'agentshop', 'agentusers', 'complaincat', 'user']) | ||
63 | + ->where($where) | ||
64 | + ->order($sort, $order) | ||
65 | + ->paginate($limit); | ||
66 | + | ||
67 | + foreach ($list as $row) { | ||
68 | + $row->visible(['id', 'user_id', 'agent_list_id', 'agent_shop_id', 'agent_user_id', 'type', 'askcat', 'asktit', 'createtime', 'status']); | ||
69 | + $row->visible(['agentlist']); | ||
70 | + $row->getRelation('agentlist')->visible(['agent_name']); | ||
71 | + $row->visible(['agentshop']); | ||
72 | + $row->getRelation('agentshop')->visible(['shop_name']); | ||
73 | + $row->visible(['agentusers']); | ||
74 | + $row->getRelation('agentusers')->visible(['jjr_name']); | ||
75 | + $row->visible(['complaincat']); | ||
76 | + $row->getRelation('complaincat')->visible(['catname']); | ||
77 | + $row->visible(['user']); | ||
78 | + $row->getRelation('user')->visible(['nickname']); | ||
79 | + } | ||
80 | + | ||
81 | + $result = array("total" => $list->total(), "rows" => $list->items()); | ||
82 | + | ||
83 | + return json($result); | ||
84 | + } | ||
85 | + return $this->view->fetch(); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * 编辑 | ||
90 | + */ | ||
91 | + public function edit($ids = null) | ||
92 | + { | ||
93 | + $row = $this->model->get($ids); | ||
94 | + if (!$row) { | ||
95 | + $this->error(__('No Results were found')); | ||
96 | + } | ||
97 | + $adminIds = $this->getDataLimitAdminIds(); | ||
98 | + if (is_array($adminIds)) { | ||
99 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
100 | + $this->error(__('You have no permission')); | ||
101 | + } | ||
102 | + } | ||
103 | + if ($this->request->isPost()) { | ||
104 | + $params = $this->request->post("row/a"); | ||
105 | + if ($params) { | ||
106 | + $params = $this->preExcludeFields($params); | ||
107 | + $result = false; | ||
108 | + Db::startTrans(); | ||
109 | + try { | ||
110 | + //是否采用模型验证 | ||
111 | + if ($this->modelValidate) { | ||
112 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
113 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
114 | + $row->validateFailException(true)->validate($validate); | ||
115 | + } | ||
116 | + | ||
117 | + $result = $row->allowField(true)->save($params); | ||
118 | + Db::commit(); | ||
119 | + } catch (ValidateException $e) { | ||
120 | + Db::rollback(); | ||
121 | + $this->error($e->getMessage()); | ||
122 | + } catch (PDOException $e) { | ||
123 | + Db::rollback(); | ||
124 | + $this->error($e->getMessage()); | ||
125 | + } catch (Exception $e) { | ||
126 | + Db::rollback(); | ||
127 | + $this->error($e->getMessage()); | ||
128 | + } | ||
129 | + if ($result !== false) { | ||
130 | + //审核通过,生成统计表 | ||
131 | + if ($params['status'] == '1') { | ||
132 | + //判断分类 | ||
133 | + if ($params['type'] == '1') { | ||
134 | + $wh['agent_list_id'] = ['=', $params['agent_list_id']]; | ||
135 | + $ctall['agent_list_id'] = $params['agent_list_id']; | ||
136 | + } | ||
137 | + if ($params['type'] == '2') { | ||
138 | + $wh['agent_shop_id'] = ['=', $params['agent_shop_id']]; | ||
139 | + $ctall['agent_shop_id'] = $params['agent_shop_id']; | ||
140 | + } | ||
141 | + if ($params['type'] == '3') { | ||
142 | + $wh['agent_user_id'] = ['=', $params['agent_user_id']]; | ||
143 | + $ctall['agent_user_id'] = $params['agent_user_id']; | ||
144 | + } | ||
145 | + $cks = Db::name('agent_user_complain_ctall') | ||
146 | + ->where($wh) | ||
147 | + ->find(); | ||
148 | + $cmpAll = Db::name('agent_user_complain_list') | ||
149 | + ->where($wh) | ||
150 | + ->where(['status' => '1']) | ||
151 | + ->count(); | ||
152 | + if (empty($cks)) { | ||
153 | + //生成统计信息 | ||
154 | + $ctall['type'] = $params['type']; | ||
155 | + $ctall['compall'] = $cmpAll ? $cmpAll : 1; | ||
156 | + $ctall['createtime'] = time(); | ||
157 | + $ctall['admin_id'] = $this->auth->id; | ||
158 | + Db::name('agent_user_complain_ctall')->insertGetId($ctall); | ||
159 | + } else { | ||
160 | + //更新统计信息 | ||
161 | + $upall['compall'] = $cmpAll; | ||
162 | + $upall['updatetime'] = time(); | ||
163 | + Db::name('agent_user_complain_ctall') | ||
164 | + ->where($wh) | ||
165 | + ->update($upall); | ||
166 | + } | ||
167 | + } | ||
168 | + $this->success(); | ||
169 | + } else { | ||
170 | + $this->error(__('No rows were updated')); | ||
171 | + } | ||
172 | + } | ||
173 | + $this->error(__('Parameter %s can not be empty', '')); | ||
174 | + } | ||
175 | + $this->view->assign("row", $row); | ||
176 | + return $this->view->fetch(); | ||
177 | + } | ||
178 | + | ||
179 | +} |
application/admin/controller/agent/Order.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use app\admin\library\Auth; | ||
7 | +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; | ||
8 | +use PhpOffice\PhpSpreadsheet\Reader\Xlsx; | ||
9 | +use PhpOffice\PhpSpreadsheet\Reader\Xls; | ||
10 | +use PhpOffice\PhpSpreadsheet\Reader\Csv; | ||
11 | +use think\Db; | ||
12 | +use think\Exception; | ||
13 | +use think\exception\PDOException; | ||
14 | +use think\exception\ValidateException; | ||
15 | +use app\common\helper\HttpHelper; | ||
16 | +use app\api\controller\v4\notary\Index; | ||
17 | + | ||
18 | +/** | ||
19 | + * | ||
20 | + * | ||
21 | + * @icon fa fa-circle-o | ||
22 | + */ | ||
23 | +class Order extends Backend | ||
24 | +{ | ||
25 | + | ||
26 | + /** | ||
27 | + * Order模型对象 | ||
28 | + * @var \app\admin\model\agent\Order | ||
29 | + */ | ||
30 | + protected $model = null; | ||
31 | + protected $dataLimit = 'auth'; | ||
32 | + protected $dataLimitField = 'admin_id'; | ||
33 | + | ||
34 | + public function _initialize() | ||
35 | + { | ||
36 | + parent::_initialize(); | ||
37 | + $this->model = new \app\admin\model\agent\Order; | ||
38 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
39 | + $this->view->assign("userNeedTypeList", $this->model->getUserNeedTypeList()); | ||
40 | + $this->view->assign("recoveryStateList", $this->model->getRecoveryStateList()); | ||
41 | + | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * 查看 | ||
46 | + */ | ||
47 | + public function index() | ||
48 | + { | ||
49 | + //设置过滤方法 | ||
50 | + $this->request->filter(['strip_tags', 'trim']); | ||
51 | + if ($this->request->isAjax()) { | ||
52 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
53 | + if ($this->request->request('keyField')) { | ||
54 | + return $this->selectpage(); | ||
55 | + } | ||
56 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
57 | + | ||
58 | + $list = $this->model | ||
59 | + ->with(['type']) | ||
60 | + ->where($where) | ||
61 | + ->order($sort, $order) | ||
62 | + ->paginate($limit); | ||
63 | + | ||
64 | + $rows = $list->items(); | ||
65 | + foreach ($rows as $kk => $vv) { | ||
66 | + //关联经纪人 | ||
67 | + if ($vv['agent_users_id'] > 0) { | ||
68 | + $agent = Db::name('agent_users') | ||
69 | + ->where(['id' => $vv['agent_users_id']]) | ||
70 | + ->field('id,jjr_name,jjr_mobile') | ||
71 | + ->find(); | ||
72 | + $rows[$kk]['jjr_name'] = $agent['jjr_name'] . '[' . $agent['jjr_mobile'] . ']'; | ||
73 | + } else { | ||
74 | + $rows[$kk]['jjr_name'] = '-'; | ||
75 | + } | ||
76 | + if ($vv['ia_pay'] == '1') { | ||
77 | + $rows[$kk]['pay_times'] = setdateTimes($vv['pay_time']); | ||
78 | + } else { | ||
79 | + $rows[$kk]['pay_times'] = '-'; | ||
80 | + } | ||
81 | + //关联贷款分类 | ||
82 | + if ($vv['loan_cat_id'] > 0) { | ||
83 | + $loncat = Db::name('loan_cat') | ||
84 | + ->where(['id' => $vv['loan_cat_id']]) | ||
85 | + ->find(); | ||
86 | + $rows[$kk]['loan_cat'] = $loncat['catname']; | ||
87 | + } else { | ||
88 | + $rows[$kk]['loan_cat'] = '-'; | ||
89 | + } | ||
90 | + //关联住房性质 | ||
91 | + if ($vv['house_cat_id'] > 0) { | ||
92 | + $housecat = Db::name('house_cat') | ||
93 | + ->where(['id' => $vv['house_cat_id']]) | ||
94 | + ->find(); | ||
95 | + $rows[$kk]['house_cat'] = $housecat['catname']; | ||
96 | + } else { | ||
97 | + $rows[$kk]['house_cat'] = '-'; | ||
98 | + } | ||
99 | + //关联当前推送到公证处状态 | ||
100 | + $step = Db::name('agent_order_send_logs') | ||
101 | + ->where(['agent_order_id' => $vv['id']]) | ||
102 | + ->order('id', 'desc') | ||
103 | + ->find(); | ||
104 | + if (empty($step)) { | ||
105 | + $sendname = '-'; | ||
106 | + } else { | ||
107 | + if ($step['step'] == 1 && $step['send_stu'] == '0') { | ||
108 | + $sendname = '用户需求推送失败'; | ||
109 | + } | ||
110 | + if ($step['step'] == 1 && $step['send_stu'] == '1') { | ||
111 | + $sendname = '用户需求推送成功'; | ||
112 | + } | ||
113 | + if ($step['step'] == 2 && $step['send_stu'] == '0') { | ||
114 | + $sendname = '不动产信息推送失败'; | ||
115 | + } | ||
116 | + if ($step['step'] == 2 && $step['send_stu'] == '1') { | ||
117 | + $sendname = '不动产信息推送成功'; | ||
118 | + } | ||
119 | + if ($step['step'] == 3 && $step['send_stu'] == '0') { | ||
120 | + $sendname = '查档报告推送失败'; | ||
121 | + } | ||
122 | + if ($step['step'] == 3 && $step['send_stu'] == '1') { | ||
123 | + $sendname = '查档报告推送成功'; | ||
124 | + } | ||
125 | + if ($step['step'] == 4 && $step['send_stu'] == '0') { | ||
126 | + $sendname = '完税报告推送失败'; | ||
127 | + } | ||
128 | + if ($step['step'] == 4 && $step['send_stu'] == '1') { | ||
129 | + $sendname = '完税报告推送成功'; | ||
130 | + } | ||
131 | + if ($step['step'] == 5 && $step['send_stu'] == '0') { | ||
132 | + $sendname = '复盘报告推送失败'; | ||
133 | + } | ||
134 | + if ($step['step'] == 5 && $step['send_stu'] == '1') { | ||
135 | + $sendname = '复盘报告推送成功'; | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + $rows[$kk]['sendname'] = $sendname; | ||
140 | + $rows[$kk]['types'] = $vv['types'] > '0' ? $vv['types'] : '-'; | ||
141 | + $rows[$kk]['agent_user'] = $vv['agent_user'] > '0' ? $vv['agent_user'] : '-'; | ||
142 | + $rows[$kk]['mobile'] = $vv['mobile'] > '0' ? $vv['mobile'] : '-'; | ||
143 | + $rows[$kk]['content'] = $vv['content'] > '0' ? $vv['content'] : ''; | ||
144 | + $rows[$kk]['remark'] = $vv['remark'] > '0' ? $vv['remark'] : ''; | ||
145 | + } | ||
146 | + | ||
147 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
148 | + | ||
149 | + return json($result); | ||
150 | + } | ||
151 | + return $this->view->fetch(); | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * 添加 | ||
156 | + */ | ||
157 | + public function add() | ||
158 | + { | ||
159 | + if ($this->request->isPost()) { | ||
160 | + $params = $this->request->post("row/a"); | ||
161 | + if ($params) { | ||
162 | + $params = $this->preExcludeFields($params); | ||
163 | + $params['order_nunber'] = getOrderSn(); | ||
164 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
165 | + $params[$this->dataLimitField] = $this->auth->id; | ||
166 | + } | ||
167 | + //判断是否选择了经纪人,选择了经纪人,添加工单所属企业 | ||
168 | + if ($params['agent_users_id'] > 0) { | ||
169 | + $params['admin_id'] = agent_users_admin_id($params['agent_users_id']); | ||
170 | + } | ||
171 | + //获得企业名称 | ||
172 | + if ($params['agent_order_type_id'] == '1' && $params['agent_name'] > 0) { | ||
173 | + $agent = Db::name('agent_list') | ||
174 | + ->where(['id' => $params['agent_name']]) | ||
175 | + ->field('id,agent_name') | ||
176 | + ->find(); | ||
177 | + $params['agent_name'] = $agent['agent_name']; | ||
178 | + } | ||
179 | + | ||
180 | + $result = false; | ||
181 | + Db::startTrans(); | ||
182 | + try { | ||
183 | + //是否采用模型验证 | ||
184 | + if ($this->modelValidate) { | ||
185 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
186 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
187 | + $this->model->validateFailException(true)->validate($validate); | ||
188 | + } | ||
189 | + $result = $this->model->allowField(true)->save($params); | ||
190 | + Db::commit(); | ||
191 | + } catch (ValidateException $e) { | ||
192 | + Db::rollback(); | ||
193 | + $this->error($e->getMessage()); | ||
194 | + } catch (PDOException $e) { | ||
195 | + Db::rollback(); | ||
196 | + $this->error($e->getMessage()); | ||
197 | + } catch (Exception $e) { | ||
198 | + Db::rollback(); | ||
199 | + $this->error($e->getMessage()); | ||
200 | + } | ||
201 | + if ($result !== false) { | ||
202 | + //审核通过并指定了经纪人 | ||
203 | + if (($params['status'] == '1' || $params['status'] == '3') && $params['agent_users_id'] > 0) { | ||
204 | + //获得工单分类名称 | ||
205 | + $ordertype = Db::name('agent_order_type') | ||
206 | + ->where(['id' => $params['agent_order_type_id']]) | ||
207 | + ->find(); | ||
208 | + $jjr_name = Db::name('agent_users') | ||
209 | + ->where(['id' => $params['agent_users_id']]) | ||
210 | + ->value('jjr_name'); | ||
211 | + $titdesc = '系统指派工单[' . $ordertype['title'] . ']'; | ||
212 | + $sendInfo = array( | ||
213 | + 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"), | ||
214 | + 'keyword1' => array('value' => urlencode($params['order_nunber']), 'color' => '#173177'), | ||
215 | + 'keyword2' => array('value' => urlencode('已指派,待处理'), 'color' => '#173177'), | ||
216 | + 'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'), | ||
217 | + 'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'), | ||
218 | + ); | ||
219 | + $wxopenid = getAgetWxOpenid($params['agent_users_id']); | ||
220 | + if ($wxopenid) { | ||
221 | + $config = get_addon_config('wechat'); | ||
222 | + $tourl = 'https://fdc.xp.yn.cn/h5/'; | ||
223 | + $ywt_appid = 'wxe1355bcf5af1bea3'; | ||
224 | + $pagepath = 'pages/home/wait/kind?id=' . $this->model->id . '&type=' . $params['agent_order_type_id'] . '&index=1'; | ||
225 | + $res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
226 | + file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-1-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
227 | + } | ||
228 | + } | ||
229 | + $this->success(); | ||
230 | + } else { | ||
231 | + $this->error(__('No rows were inserted')); | ||
232 | + } | ||
233 | + } | ||
234 | + $this->error(__('Parameter %s can not be empty', '')); | ||
235 | + } | ||
236 | + return $this->view->fetch(); | ||
237 | + } | ||
238 | + | ||
239 | + /*** | ||
240 | + * 编辑(old) | ||
241 | + * | ||
242 | + */ | ||
243 | +// public function edit($ids = null) | ||
244 | +// { | ||
245 | +// $row = $this->model->get($ids); | ||
246 | +// $row['types'] = $row['types'] > '0' ? $row['types'] : ''; | ||
247 | +// $row['agent_user'] = $row['agent_user'] > '0' ? $row['agent_user'] : ''; | ||
248 | +// $row['mobile'] = $row['mobile'] > '0' ? $row['mobile'] : ''; | ||
249 | +// $row['content'] = $row['content'] > '0' ? $row['content'] : ''; | ||
250 | +// $row['remark'] = $row['remark'] > '0' ? $row['remark'] : ''; | ||
251 | +// if (!$row) { | ||
252 | +// $this->error(__('No Results were found')); | ||
253 | +// } | ||
254 | +// $adminIds = $this->getDataLimitAdminIds(); | ||
255 | +// if (is_array($adminIds)) { | ||
256 | +// if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
257 | +// $this->error(__('You have no permission')); | ||
258 | +// } | ||
259 | +// } | ||
260 | +// if ($this->request->isPost()) { | ||
261 | +// $params = $this->request->post("row/a"); | ||
262 | +// if ($params) { | ||
263 | +// $params = $this->preExcludeFields($params); | ||
264 | +// //判断是否选择了经纪人,选择了经纪人,添加工单所属企业 | ||
265 | +// if ($params['agent_users_id'] > 0) { | ||
266 | +// $params['admin_id'] = agent_users_admin_id($params['agent_users_id']); | ||
267 | +// } | ||
268 | +// $result = false; | ||
269 | +// Db::startTrans(); | ||
270 | +// try { | ||
271 | +// //是否采用模型验证 | ||
272 | +// if ($this->modelValidate) { | ||
273 | +// $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
274 | +// $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
275 | +// $row->validateFailException(true)->validate($validate); | ||
276 | +// } | ||
277 | +// if ($params['status'] == 1 && $params['agent_users_id'] > 0) { | ||
278 | +// $params['status'] = 3; | ||
279 | +// } | ||
280 | +// | ||
281 | +// $result = $row->save($params); | ||
282 | +// if ($params['status'] == 1) { | ||
283 | +// $str = '工单通过审核'; | ||
284 | +// } | ||
285 | +// if ($params['status'] == 2) { | ||
286 | +// $str = '工单未通过审核'; | ||
287 | +// } | ||
288 | +// if ($params['status'] == 3) { | ||
289 | +// $str = '工单已指派'; | ||
290 | +// } | ||
291 | +// if ($params['status'] == 8) { | ||
292 | +// $str = '工单不通过,退款金额原路返回'; | ||
293 | +// } | ||
294 | +// | ||
295 | +// Db::name('agent_order_log')->insert([ | ||
296 | +// 'agent_order_id' => $ids, | ||
297 | +// 'admin_id' => $this->auth->id, | ||
298 | +// 'content' => $str, | ||
299 | +// 'createtime' => time(), | ||
300 | +// 'step' => 2, | ||
301 | +// 'agent_user_id' => $params['agent_users_id'] ? $params['agent_users_id'] : 0, | ||
302 | +// ]); | ||
303 | +// | ||
304 | +// //判断是否已支付,已支付则退款 | ||
305 | +// if ($params['status'] == 8 && $row['ia_pay'] == '1') { | ||
306 | +// //支付金额 | ||
307 | +// $paylog = Db::name('workorder_userpay') | ||
308 | +// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']]) | ||
309 | +// ->find(); | ||
310 | +// if (!empty($paylog)) { | ||
311 | +// //退款处理 | ||
312 | +// $pay_fee = $paylog['price']; | ||
313 | +// $refund_fee = $pay_fee; | ||
314 | +// $order_sn = $paylog['ordersn']; | ||
315 | +// $pay_type = 'wechat'; | ||
316 | +// $reason = '工单审核不通过,退回保证金'; | ||
317 | +// $notifyurl = 'https://fdc.xp.yn.cn/api/index/refundNotifyx';//退款回调地址 | ||
318 | +// //直接调用退款方法传参即可 | ||
319 | +// $response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($paylog['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp'); | ||
320 | +// $response = json_encode($response); | ||
321 | +// $response = json_decode($response, true); | ||
322 | +// file_put_contents("pcl_repay_fdc_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
323 | +// if (!empty($response['return_code'] == 'SUCCESS')) { | ||
324 | +// //退款成功,更新退款记录 | ||
325 | +// $addtime = time(); | ||
326 | +// $relogs['uptime'] = $addtime; | ||
327 | +// $relogs['is_refund'] = 1; | ||
328 | +// $relogs['out_refund_no'] = $response['out_refund_no']; | ||
329 | +// $relogs['refund_id'] = $response['refund_id']; | ||
330 | +// $relogs['refund_fee'] = $response['refund_fee']; | ||
331 | +// $relogs['refund_time'] = $addtime; | ||
332 | +// $relogs['admin'] = $this->auth->id; | ||
333 | +// Db::name('workorder_userpay') | ||
334 | +// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']]) | ||
335 | +// ->update($relogs); | ||
336 | +// //更新工单表 | ||
337 | +// $order['is_refund'] = 1; | ||
338 | +// $order['refund_time'] = $addtime; | ||
339 | +// Db::name('agent_order') | ||
340 | +// ->where(['id' => $row['id']]) | ||
341 | +// ->update($order); | ||
342 | +// } else { | ||
343 | +// $this->error('退款失败'); | ||
344 | +// } | ||
345 | +// } | ||
346 | +// } | ||
347 | +// | ||
348 | +// Db::commit(); | ||
349 | +// } catch (ValidateException $e) { | ||
350 | +// Db::rollback(); | ||
351 | +// $this->error($e->getMessage()); | ||
352 | +// } catch (PDOException $e) { | ||
353 | +// Db::rollback(); | ||
354 | +// $this->error($e->getMessage()); | ||
355 | +// } catch (Exception $e) { | ||
356 | +// Db::rollback(); | ||
357 | +// $this->error($e->getMessage()); | ||
358 | +// } | ||
359 | +// if ($result !== false) { | ||
360 | +// //审核通过并指定了经纪人 | ||
361 | +// if (($params['status'] == '1' || $params['status'] == '3') && $params['agent_users_id'] > 0) { | ||
362 | +// //获得工单分类名称 | ||
363 | +// $ordertype = Db::name('agent_order_type') | ||
364 | +// ->where(['id' => $params['agent_order_type_id']]) | ||
365 | +// ->find(); | ||
366 | +// $jjr_name = Db::name('agent_users') | ||
367 | +// ->where(['id' => $params['agent_users_id']]) | ||
368 | +// ->value('jjr_name'); | ||
369 | +// $titdesc = '系统指派工单[' . $ordertype['title'] . ']'; | ||
370 | +// $sendInfo = array( | ||
371 | +// 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"), | ||
372 | +// 'keyword1' => array('value' => urlencode($row['order_nunber']), 'color' => '#173177'), | ||
373 | +// 'keyword2' => array('value' => urlencode('已指派,待处理'), 'color' => '#173177'), | ||
374 | +// 'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'), | ||
375 | +// 'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'), | ||
376 | +// ); | ||
377 | +// $wxopenid = getAgetWxOpenid($params['agent_users_id']); | ||
378 | +// if ($wxopenid) { | ||
379 | +// $config = get_addon_config('wechat'); | ||
380 | +// $tourl = 'https://fdc.xp.yn.cn/h5/'; | ||
381 | +// $ywt_appid = 'wxe1355bcf5af1bea3'; | ||
382 | +// $pagepath = 'pages/home/wait/kind?id=' . $row['id'] . '&type=' . $params['agent_order_type_id'] . '&index=1'; | ||
383 | +// $res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
384 | +// file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
385 | +// } | ||
386 | +// } | ||
387 | +// $this->success(); | ||
388 | +// } else { | ||
389 | +// $this->error(__('No rows were updated')); | ||
390 | +// } | ||
391 | +// } | ||
392 | +// $this->error(__('Parameter %s can not be empty', '')); | ||
393 | +// } | ||
394 | +// $this->view->assign("row", $row); | ||
395 | +// return $this->view->fetch(); | ||
396 | +// } | ||
397 | + | ||
398 | + /*** | ||
399 | + * 编辑 | ||
400 | + * | ||
401 | + */ | ||
402 | + public function edit($ids = null) | ||
403 | + { | ||
404 | + $row = $this->model->get($ids); | ||
405 | + $row['types'] = $row['types'] > '0' ? $row['types'] : ''; | ||
406 | + $row['agent_user'] = $row['agent_user'] > '0' ? $row['agent_user'] : ''; | ||
407 | + $row['mobile'] = $row['mobile'] > '0' ? $row['mobile'] : ''; | ||
408 | + $row['content'] = $row['content'] > '0' ? $row['content'] : ''; | ||
409 | + $row['remark'] = $row['remark'] > '0' ? $row['remark'] : ''; | ||
410 | + //获得推送公证处状态 | ||
411 | + $step = Db::name('agent_order_send_logs') | ||
412 | + ->where(['agent_order_id' => $row['id']]) | ||
413 | + ->order('id', 'desc') | ||
414 | + ->find(); | ||
415 | + | ||
416 | + if (!$row) { | ||
417 | + $this->error(__('No Results were found')); | ||
418 | + } | ||
419 | + $adminIds = $this->getDataLimitAdminIds(); | ||
420 | + if (is_array($adminIds)) { | ||
421 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
422 | + $this->error(__('You have no permission')); | ||
423 | + } | ||
424 | + } | ||
425 | + if ($this->request->isPost()) { | ||
426 | + $params = $this->request->post("row/a"); | ||
427 | + if ($params) { | ||
428 | + $params = $this->preExcludeFields($params); | ||
429 | + //判断是否选择了经纪人,选择了经纪人,添加工单所属企业 | ||
430 | + if ($params['agent_users_id'] > 0) { | ||
431 | + $params['admin_id'] = agent_users_admin_id($params['agent_users_id']); | ||
432 | + } | ||
433 | + if (isset($params['pclOfficeSendv2'])) { | ||
434 | + $pclOfficeSendv2 = $params['pclOfficeSendv2']; | ||
435 | + unset($params['pclOfficeSendv2']); | ||
436 | + } | ||
437 | + if (isset($params['pclOfficeSendv3'])) { | ||
438 | + $pclOfficeSendv3 = $params['pclOfficeSendv3']; | ||
439 | + unset($params['pclOfficeSendv3']); | ||
440 | + } | ||
441 | + if (isset($params['pclOfficeSendv4'])) { | ||
442 | + $pclOfficeSendv4 = $params['pclOfficeSendv4']; | ||
443 | + unset($params['pclOfficeSendv4']); | ||
444 | + } | ||
445 | + if (isset($params['pclOfficeSendv5'])) { | ||
446 | + $pclOfficeSendv5 = $params['pclOfficeSendv5']; | ||
447 | + unset($params['pclOfficeSendv5']); | ||
448 | + } | ||
449 | + $result = false; | ||
450 | + Db::startTrans(); | ||
451 | + try { | ||
452 | + //是否采用模型验证 | ||
453 | + if ($this->modelValidate) { | ||
454 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
455 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
456 | + $row->validateFailException(true)->validate($validate); | ||
457 | + } | ||
458 | + | ||
459 | + $result = $row->save($params); | ||
460 | + $statusList = $this->model->getStatusList(); | ||
461 | + $str = $statusList[$params['status']]; | ||
462 | + | ||
463 | + $step_id = 0; | ||
464 | + $step = Db::name("agent_order_log")->where("agent_order_id", $ids)->order("step desc,id desc")->value("step"); | ||
465 | + if ($step) { | ||
466 | + $step_id = $step + 1; | ||
467 | + } | ||
468 | + | ||
469 | + Db::name('agent_order_log')->insert([ | ||
470 | + 'agent_order_id' => $ids, | ||
471 | + 'content' => $str, | ||
472 | + 'user_id' => $row['user_id'], | ||
473 | + 'createtime' => time(), | ||
474 | + 'admin_id' => agent_users_admin_id($params['agent_users_id']), | ||
475 | + 'step' => $step_id, | ||
476 | + 'write_status' => $params['status'], | ||
477 | + 'agent_user_id' => $params['agent_users_id'] ? $params['agent_users_id'] : 0, | ||
478 | + ]); | ||
479 | + | ||
480 | + //判断是否已支付,已支付则退款 | ||
481 | +// if ($params['status'] == 8 && $row['ia_pay'] == '1') { | ||
482 | +// //支付金额 | ||
483 | +// $paylog = Db::name('workorder_userpay') | ||
484 | +// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']]) | ||
485 | +// ->find(); | ||
486 | +// if (!empty($paylog)) { | ||
487 | +// //退款处理 | ||
488 | +// $pay_fee = $paylog['price']; | ||
489 | +// $refund_fee = $pay_fee; | ||
490 | +// $order_sn = $paylog['ordersn']; | ||
491 | +// $pay_type = 'wechat'; | ||
492 | +// $reason = '工单审核不通过,退回保证金'; | ||
493 | +// $notifyurl = 'https://fdc.xp.yn.cn/api/index/refundNotifyx';//退款回调地址 | ||
494 | +// //直接调用退款方法传参即可 | ||
495 | +// $response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($paylog['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp'); | ||
496 | +// $response = json_encode($response); | ||
497 | +// $response = json_decode($response, true); | ||
498 | +// file_put_contents("pcl_repay_fdc_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
499 | +// if (!empty($response['return_code'] == 'SUCCESS')) { | ||
500 | +// //退款成功,更新退款记录 | ||
501 | +// $addtime = time(); | ||
502 | +// $relogs['uptime'] = $addtime; | ||
503 | +// $relogs['is_refund'] = 1; | ||
504 | +// $relogs['out_refund_no'] = $response['out_refund_no']; | ||
505 | +// $relogs['refund_id'] = $response['refund_id']; | ||
506 | +// $relogs['refund_fee'] = $response['refund_fee']; | ||
507 | +// $relogs['refund_time'] = $addtime; | ||
508 | +// $relogs['admin'] = $this->auth->id; | ||
509 | +// Db::name('workorder_userpay') | ||
510 | +// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']]) | ||
511 | +// ->update($relogs); | ||
512 | +// //更新工单表 | ||
513 | +// $order['is_refund'] = 1; | ||
514 | +// $order['refund_time'] = $addtime; | ||
515 | +// Db::name('agent_order') | ||
516 | +// ->where(['id' => $row['id']]) | ||
517 | +// ->update($order); | ||
518 | +// } else { | ||
519 | +// $this->error('退款失败'); | ||
520 | +// } | ||
521 | +// } | ||
522 | +// } | ||
523 | + | ||
524 | + Db::commit(); | ||
525 | + } catch (ValidateException $e) { | ||
526 | + Db::rollback(); | ||
527 | + $this->error($e->getMessage()); | ||
528 | + } catch (PDOException $e) { | ||
529 | + Db::rollback(); | ||
530 | + $this->error($e->getMessage()); | ||
531 | + } catch (Exception $e) { | ||
532 | + Db::rollback(); | ||
533 | + $this->error($e->getMessage()); | ||
534 | + } | ||
535 | + if ($result !== false) { | ||
536 | + //获得工单信息 | ||
537 | + $orders = Db::name('agent_order')->where(['id' => $row['id']])->find(); | ||
538 | + $titdesc = $orders['order_nunber']; | ||
539 | + if ($params['status'] == '1') { | ||
540 | + $titdesc = '工单审核通过'; | ||
541 | + } | ||
542 | + if ($params['status'] == '2') { | ||
543 | + $titdesc = '工单审核被拒绝'; | ||
544 | + } | ||
545 | + | ||
546 | + | ||
547 | + //第1步 用户需求信息审核成功,调用接口推给公证处 | ||
548 | + $Office = new Index(); | ||
549 | + if ($params['status'] == '1') { | ||
550 | + $titdesc = '工单审核通过,公证处办理中'; | ||
551 | + //判断是否推送过了,推送日志表agent_order_send_logs | ||
552 | + $cks_send = Db::name('agent_order_send_logs') | ||
553 | + ->where(['agent_order_id' => $row['id'], 'send_stu' => 1, 'step' => 1]) | ||
554 | + ->find(); | ||
555 | + if (empty($cks_send)) { | ||
556 | + //1获得token | ||
557 | + $token = $Office->getOfficeToken(); | ||
558 | + while (empty($token)) { | ||
559 | + $token = $Office->getOfficeToken(); | ||
560 | + } | ||
561 | + //获得推送数据 | ||
562 | + $sendData = $Office->notifyNewOrder($row['id']); | ||
563 | + | ||
564 | + $url = "https://gz.hxgzc.cn:34443/capitalManage/services/createOrder"; | ||
565 | + if (!empty($token) && !empty($sendData)) { | ||
566 | + $res = HttpHelper::curl($url, 'POST', $sendData, [], $token); | ||
567 | + $resArr = json_decode(stripslashes($res), true); | ||
568 | + | ||
569 | + if ($resArr['succeed'] == true) { | ||
570 | + $slogs['send_stu'] = 1; | ||
571 | + } else { | ||
572 | + $slogs['send_stu'] = 0; | ||
573 | + } | ||
574 | + $slogs['agent_order_id'] = $row['id']; | ||
575 | + $slogs['createtime'] = time(); | ||
576 | + $slogs['step'] = 1; | ||
577 | + $slogs['reback_msg'] = $res; | ||
578 | + | ||
579 | + $logs = Db::name('agent_order_send_logs')->insertGetId($slogs); | ||
580 | + | ||
581 | + } | ||
582 | + } | ||
583 | + } | ||
584 | + //2、不动产信息审核通过,推送公证处 | ||
585 | + if ($pclOfficeSendv2 == 1) { | ||
586 | + $titdesc = '不动产信息审核通过,公证处办理中'; | ||
587 | + //1获得token | ||
588 | + $token = $Office->getOfficeToken(); | ||
589 | + while (empty($token)) { | ||
590 | + $token = $Office->getOfficeToken(); | ||
591 | + } | ||
592 | + //获得推送数据 | ||
593 | + $sendData = $Office->realEstateUpdate($row['id']); | ||
594 | + | ||
595 | + $url = "https://gz.hxgzc.cn:34443/capitalManage/services/realEstateUpdate"; | ||
596 | + if (!empty($token) && !empty($sendData)) { | ||
597 | + $res = HttpHelper::curl($url, 'POST', $sendData, [], $token); | ||
598 | + $resArr = json_decode(stripslashes($res), true); | ||
599 | + | ||
600 | + if ($resArr['succeed'] == true) { | ||
601 | + $slogs['send_stu'] = 1; | ||
602 | + } else { | ||
603 | + $slogs['send_stu'] = 0; | ||
604 | + } | ||
605 | + $slogs['agent_order_id'] = $row['id']; | ||
606 | + $slogs['createtime'] = time(); | ||
607 | + $slogs['step'] = 2; | ||
608 | + $slogs['reback_msg'] = $res; | ||
609 | + | ||
610 | + $logs = Db::name('agent_order_send_logs')->insertGetId($slogs); | ||
611 | + | ||
612 | + } | ||
613 | + } | ||
614 | + //3、推送查档报告 | ||
615 | + if ($pclOfficeSendv3 == 1) { | ||
616 | + $titdesc = '查档报告审核通过,公证处办理中'; | ||
617 | + //1获得token | ||
618 | + $token = $Office->getOfficeToken(); | ||
619 | + while (empty($token)) { | ||
620 | + $token = $Office->getOfficeToken(); | ||
621 | + } | ||
622 | + //获得推送数据 | ||
623 | + $sendData = $Office->checkReportUpdate($row['id']); | ||
624 | + | ||
625 | + $url = "https://gz.hxgzc.cn:34443/capitalManage/services/checkReportUpdate"; | ||
626 | + if (!empty($token) && !empty($sendData)) { | ||
627 | + $res = HttpHelper::curl($url, 'POST', $sendData, [], $token); | ||
628 | + $resArr = json_decode(stripslashes($res), true); | ||
629 | + | ||
630 | + if ($resArr['succeed'] == true) { | ||
631 | + $slogs['send_stu'] = 1; | ||
632 | + } else { | ||
633 | + $slogs['send_stu'] = 0; | ||
634 | + } | ||
635 | + $slogs['agent_order_id'] = $row['id']; | ||
636 | + $slogs['createtime'] = time(); | ||
637 | + $slogs['step'] = 3; | ||
638 | + $slogs['reback_msg'] = $res; | ||
639 | + | ||
640 | + $logs = Db::name('agent_order_send_logs')->insertGetId($slogs); | ||
641 | + | ||
642 | + } | ||
643 | + } | ||
644 | + //4、推送完税报告 | ||
645 | + if ($pclOfficeSendv4 == 1) { | ||
646 | + $titdesc = '完税报告审核通过,公证处办理中'; | ||
647 | + //1获得token | ||
648 | + $token = $Office->getOfficeToken(); | ||
649 | + while (empty($token)) { | ||
650 | + $token = $Office->getOfficeToken(); | ||
651 | + } | ||
652 | + //获得推送数据 | ||
653 | + $sendData = $Office->taxPaidReportUpdate($row['id']); | ||
654 | + | ||
655 | + $url = "https://gz.hxgzc.cn:34443/capitalManage/services/taxPaidReportUpdate"; | ||
656 | + if (!empty($token) && !empty($sendData)) { | ||
657 | + $res = HttpHelper::curl($url, 'POST', $sendData, [], $token); | ||
658 | + $resArr = json_decode(stripslashes($res), true); | ||
659 | + | ||
660 | + if ($resArr['succeed'] == true) { | ||
661 | + $slogs['send_stu'] = 1; | ||
662 | + } else { | ||
663 | + $slogs['send_stu'] = 0; | ||
664 | + } | ||
665 | + $slogs['agent_order_id'] = $row['id']; | ||
666 | + $slogs['createtime'] = time(); | ||
667 | + $slogs['step'] = 4;// | ||
668 | + $slogs['reback_msg'] = $res; | ||
669 | + | ||
670 | + $logs = Db::name('agent_order_send_logs')->insertGetId($slogs); | ||
671 | + | ||
672 | + } | ||
673 | + } | ||
674 | + //5、推送复盘报告 | ||
675 | + if ($pclOfficeSendv5 == 1) { | ||
676 | + $titdesc = '复盘信息审核通过,公证处办理中'; | ||
677 | + //1获得token | ||
678 | + $token = $Office->getOfficeToken(); | ||
679 | + while (empty($token)) { | ||
680 | + $token = $Office->getOfficeToken(); | ||
681 | + } | ||
682 | + //获得推送数据 | ||
683 | + $sendData = $Office->orderMatchReportUpdate($row['id']); | ||
684 | + | ||
685 | + $url = "https://gz.hxgzc.cn:34443/capitalManage/services/orderMatchReportUpdate"; | ||
686 | + if (!empty($token) && !empty($sendData)) { | ||
687 | + $res = HttpHelper::curl($url, 'POST', $sendData, [], $token); | ||
688 | + $resArr = json_decode(stripslashes($res), true); | ||
689 | + | ||
690 | + if ($resArr['succeed'] == true) { | ||
691 | + $slogs['send_stu'] = 1; | ||
692 | + } else { | ||
693 | + $slogs['send_stu'] = 0; | ||
694 | + } | ||
695 | + $slogs['agent_order_id'] = $row['id']; | ||
696 | + $slogs['createtime'] = time(); | ||
697 | + $slogs['step'] = 5;//复盘 | ||
698 | + $slogs['reback_msg'] = $res; | ||
699 | + | ||
700 | + $logs = Db::name('agent_order_send_logs')->insertGetId($slogs); | ||
701 | + | ||
702 | + } | ||
703 | + } | ||
704 | + | ||
705 | + | ||
706 | + //审核通过并指定了经纪人 | ||
707 | +// if (($params['status'] == '1' || $params['status'] == '3') && $params['agent_users_id'] > 0) { | ||
708 | +// //获得工单分类名称 | ||
709 | +// $ordertype = Db::name('agent_order_type') | ||
710 | +// ->where(['id' => $params['agent_order_type_id']]) | ||
711 | +// ->find(); | ||
712 | +// $jjr_name = Db::name('agent_users') | ||
713 | +// ->where(['id' => $params['agent_users_id']]) | ||
714 | +// ->value('jjr_name'); | ||
715 | +// $titdesc = '系统指派工单[' . $ordertype['title'] . ']'; | ||
716 | +// $sendInfo = array( | ||
717 | +// 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"), | ||
718 | +// 'keyword1' => array('value' => urlencode($row['order_nunber']), 'color' => '#173177'), | ||
719 | +// 'keyword2' => array('value' => urlencode('已指派,待处理'), 'color' => '#173177'), | ||
720 | +// 'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'), | ||
721 | +// 'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'), | ||
722 | +// ); | ||
723 | +// $wxopenid = getAgetWxOpenid($params['agent_users_id']); | ||
724 | +// if ($wxopenid) { | ||
725 | +// $config = get_addon_config('wechat'); | ||
726 | +// $tourl = 'https://fdc.xp.yn.cn/h5/'; | ||
727 | +// $ywt_appid = 'wxe1355bcf5af1bea3'; | ||
728 | +// $pagepath = 'pages/home/wait/kind?id=' . $row['id'] . '&type=' . $params['agent_order_type_id'] . '&index=1'; | ||
729 | +// $res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
730 | +// file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
731 | +// } | ||
732 | +// } | ||
733 | + | ||
734 | + //推送公众号模板信息给工单管理经纪人 | ||
735 | + $this->senWxmsgToAgentUser($orders, $titdesc); | ||
736 | + $this->success(); | ||
737 | + } else { | ||
738 | + $this->error(__('No rows were updated')); | ||
739 | + } | ||
740 | + } | ||
741 | + $this->error(__('Parameter %s can not be empty', '')); | ||
742 | + } | ||
743 | + $this->view->assign("row", $row); | ||
744 | + $this->view->assign("step", $step); | ||
745 | + return $this->view->fetch(); | ||
746 | + } | ||
747 | + | ||
748 | + /*** | ||
749 | + * 公众号推送工单信息给经纪人 | ||
750 | + */ | ||
751 | + private function senWxmsgToAgentUser($order, $titdesc) | ||
752 | + { | ||
753 | + //获得工单分类名称 | ||
754 | + $ordertype = Db::name('agent_order_type') | ||
755 | + ->where(['id' => $order['agent_order_type_id']]) | ||
756 | + ->find(); | ||
757 | + $jjr_name = Db::name('agent_users') | ||
758 | + ->where(['id' => $order['agent_users_id']]) | ||
759 | + ->value('jjr_name'); | ||
760 | + $sendInfo = array( | ||
761 | + 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"), | ||
762 | + 'keyword1' => array('value' => urlencode($order['order_nunber']), 'color' => '#173177'), | ||
763 | + 'keyword2' => array('value' => urlencode($titdesc), 'color' => '#173177'), | ||
764 | + 'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'), | ||
765 | + 'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'), | ||
766 | + ); | ||
767 | + $wxopenid = getAgetWxOpenid($order['agent_users_id']); | ||
768 | + if ($wxopenid) { | ||
769 | + $config = get_addon_config('wechat'); | ||
770 | + $tourl = 'https://fdc.xp.yn.cn/h5/'; | ||
771 | + $ywt_appid = 'wxe1355bcf5af1bea3'; | ||
772 | + $pagepath = 'pages/order/order_details?id=' . $order['id']; | ||
773 | + $res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
774 | + //file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
775 | + } | ||
776 | + } | ||
777 | + | ||
778 | + /** | ||
779 | + * 导入excel数据 | ||
780 | + */ | ||
781 | + public function import() | ||
782 | + { | ||
783 | + | ||
784 | + $file = $this->request->request('file'); | ||
785 | + if (!$file) { | ||
786 | + $this->error(__('Parameter %s can not be empty', 'file')); | ||
787 | + } | ||
788 | + $filePath = ROOT_PATH . DS . 'public' . DS . $file; | ||
789 | + if (!is_file($filePath)) { | ||
790 | + $this->error(__('No results were found')); | ||
791 | + } | ||
792 | + | ||
793 | + if (!is_file($filePath)) { | ||
794 | + $this->error('找不到数据文件,请重新上传'); | ||
795 | + } | ||
796 | + | ||
797 | + //实例化reader | ||
798 | + $ext = pathinfo($filePath, PATHINFO_EXTENSION); | ||
799 | + if (!in_array($ext, ['xls', 'xlsx'])) { | ||
800 | + $this->error('不支持的数据格式'); | ||
801 | + } | ||
802 | + if ($ext === 'xls') { | ||
803 | + $reader = new Xls(); | ||
804 | + } else { | ||
805 | + $reader = new Xlsx(); | ||
806 | + } | ||
807 | + //读取EXCEl的内容 | ||
808 | + $PHPExcel = $reader->load($filePath); | ||
809 | + if (!$PHPExcel) { | ||
810 | + $this->error('表格内没有数据内容'); | ||
811 | + } | ||
812 | + $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表 | ||
813 | + $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 | ||
814 | + $allRow = $currentSheet->getHighestRow(); //取得一共有多少行 | ||
815 | + $maxColumnNumber = Coordinate::columnIndexFromString($allColumn); | ||
816 | + $fields = []; | ||
817 | + //获得表第1行栏目名称 | ||
818 | + for ($currentRow = 1; $currentRow <= 1; $currentRow++) { | ||
819 | + for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { | ||
820 | + $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); | ||
821 | + $fields[] = $val; | ||
822 | + } | ||
823 | + } | ||
824 | + //获得从第2行起内容列表数组 | ||
825 | + for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) { | ||
826 | + $values = []; | ||
827 | + for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { | ||
828 | + $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); | ||
829 | + $values[] = is_null($val) ? '0' : $val; | ||
830 | + } | ||
831 | + | ||
832 | + //循环保存数据到数据库 | ||
833 | + $data['agent_order_type_id'] = $this->getcatIds($values[1]); | ||
834 | + $data['order_nunber'] = getOrderSn(); | ||
835 | + | ||
836 | + $data['user_name'] = $values[2]; | ||
837 | + $data['cqr_mobile'] = $values[3]; | ||
838 | + $data['agent_user'] = $values[4]; | ||
839 | + $data['mobile'] = $values[5] > '0' ? $values[5] : ''; | ||
840 | + | ||
841 | + if ($data['agent_order_type_id'] == 5 && $values[6] > '0') { | ||
842 | + $data['loan_cat_id'] = $this->getLoancatIds($values[6]); | ||
843 | + } else { | ||
844 | + $data['loan_cat_id'] = ''; | ||
845 | + } | ||
846 | + if ($data['agent_order_type_id'] == 1 && $values[7] > '0') { | ||
847 | + $data['house_cat_id'] = $this->getHousecatIds($values[7]); | ||
848 | + } else { | ||
849 | + $data['house_cat_id'] = ''; | ||
850 | + } | ||
851 | + | ||
852 | + $data['agent_name'] = $values[8] > '0' ? $values[8] : ''; | ||
853 | + $data['agent_user_name'] = $values[9] > '0' ? $values[9] : ''; | ||
854 | + $data['agent_mobile'] = $values[10] > '0' ? $values[10] : ''; | ||
855 | + | ||
856 | + $data['house_area'] = $values[11] > '0' ? $values[11] : ''; | ||
857 | + $data['house_price'] = $values[12] > '0' ? $values[12] : ''; | ||
858 | + | ||
859 | + $data['content'] = $values[13] > '0' ? $values[13] : ''; | ||
860 | + $data['remark'] = $values[14] > '0' ? $values[14] : ''; | ||
861 | + | ||
862 | + $data['is_import'] = 1; | ||
863 | + $data['createtime'] = time(); | ||
864 | + | ||
865 | + //判断订单号是否存在 | ||
866 | + $cks = Db::name('agent_order') | ||
867 | + ->where(['order_nunber' => $data['order_nunber']]) | ||
868 | + ->find(); | ||
869 | + if (empty($cks)) { | ||
870 | + $rs = Db::name('agent_order')->insertGetId($data); | ||
871 | + } | ||
872 | + | ||
873 | + } | ||
874 | + $this->success('导入成功'); | ||
875 | + } | ||
876 | + | ||
877 | + /** | ||
878 | + * 配置分类 | ||
879 | + * 工单分类 | ||
880 | + */ | ||
881 | + protected function getcatIds($data) | ||
882 | + { | ||
883 | + $wh['title'] = ['=', $data]; | ||
884 | + $cat = Db::name('agent_order_type') | ||
885 | + ->where($wh) | ||
886 | + ->find(); | ||
887 | + if (empty($cat)) { | ||
888 | + $wh2['title'] = ['like', '%' . $data . '%']; | ||
889 | + $cat = Db::name('agent_order_type') | ||
890 | + ->where($wh2) | ||
891 | + ->find(); | ||
892 | + } | ||
893 | + $cat_id = !empty($cat) ? $cat['id'] : 1; | ||
894 | + | ||
895 | + return $cat_id; | ||
896 | + } | ||
897 | + | ||
898 | + /** | ||
899 | + * 贷款分类 | ||
900 | + * | ||
901 | + */ | ||
902 | + protected function getLoancatIds($data) | ||
903 | + { | ||
904 | + $wh['catname'] = ['=', $data]; | ||
905 | + $cat = Db::name('loan_cat') | ||
906 | + ->where($wh) | ||
907 | + ->find(); | ||
908 | + if (empty($cat)) { | ||
909 | + $wh2['catname'] = ['like', '%' . $data . '%']; | ||
910 | + $cat = Db::name('loan_cat') | ||
911 | + ->where($wh2) | ||
912 | + ->find(); | ||
913 | + } | ||
914 | + $cat_id = !empty($cat) ? $cat['id'] : 1; | ||
915 | + | ||
916 | + return $cat_id; | ||
917 | + } | ||
918 | + | ||
919 | + /** | ||
920 | + * 房子性质分类 | ||
921 | + * | ||
922 | + */ | ||
923 | + protected function getHousecatIds($data) | ||
924 | + { | ||
925 | + $wh['catname'] = ['=', $data]; | ||
926 | + $cat = Db::name('house_cat') | ||
927 | + ->where($wh) | ||
928 | + ->find(); | ||
929 | + if (empty($cat)) { | ||
930 | + $wh2['catname'] = ['like', '%' . $data . '%']; | ||
931 | + $cat = Db::name('house_cat') | ||
932 | + ->where($wh2) | ||
933 | + ->find(); | ||
934 | + } | ||
935 | + $cat_id = !empty($cat) ? $cat['id'] : 1; | ||
936 | + | ||
937 | + return $cat_id; | ||
938 | + } | ||
939 | + | ||
940 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Orderlog extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Orderlog模型对象 | ||
18 | + * @var \app\admin\model\agent\Orderlog | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Orderlog; | ||
26 | + | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * 查看 | ||
31 | + */ | ||
32 | + public function index() | ||
33 | + { | ||
34 | + //设置过滤方法 | ||
35 | + $this->request->filter(['strip_tags', 'trim']); | ||
36 | + if ($this->request->isAjax()) { | ||
37 | + $appid = $this->request->param('app_id', 0); | ||
38 | + if ($appid > 0) { | ||
39 | + $wh['agent_order_id'] = ['=', $appid]; | ||
40 | + } else { | ||
41 | + $wh = " 1=1 "; | ||
42 | + } | ||
43 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
44 | + if ($this->request->request('keyField')) { | ||
45 | + return $this->selectpage(); | ||
46 | + } | ||
47 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
48 | + | ||
49 | + $list = $this->model | ||
50 | + ->where($where) | ||
51 | + ->where($wh) | ||
52 | + ->order('id', 'asc') | ||
53 | + ->paginate($limit); | ||
54 | + | ||
55 | + $rows = $list->items(); | ||
56 | + foreach ($rows as $kk => $vv) { | ||
57 | + //关联发布人 | ||
58 | + $oinfo = Db::name('agent_order') | ||
59 | + ->where(['id' => $vv['agent_order_id']]) | ||
60 | + ->find(); | ||
61 | + $rows[$kk]['user_name'] = $oinfo['user_name']; | ||
62 | + $rows[$kk]['mobile'] = $oinfo['mobile']; | ||
63 | + //处理人信息 | ||
64 | + if ($vv['agent_user_id'] > 0) { | ||
65 | + $agent = Db::name('agent_users') | ||
66 | + ->where(['id' => $vv['agent_user_id']]) | ||
67 | + ->field('id,jjr_name,jjr_mobile') | ||
68 | + ->find(); | ||
69 | + $rows[$kk]['jjr_name'] = $agent['jjr_name'] . '[' . $agent['jjr_mobile'] . ']'; | ||
70 | + } else { | ||
71 | + $rows[$kk]['jjr_name'] = '-'; | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
76 | + | ||
77 | + return json($result); | ||
78 | + } | ||
79 | + return $this->view->fetch(); | ||
80 | + } | ||
81 | + | ||
82 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 工单推送公证处日志 | ||
9 | + * | ||
10 | + * @icon fa fa-circle-o | ||
11 | + */ | ||
12 | +class Ordersendlog extends Backend | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * Ordersendlog模型对象 | ||
17 | + * @var \app\admin\model\agent\Ordersendlog | ||
18 | + */ | ||
19 | + protected $model = null; | ||
20 | + | ||
21 | + public function _initialize() | ||
22 | + { | ||
23 | + parent::_initialize(); | ||
24 | + $this->model = new \app\admin\model\agent\Ordersendlog; | ||
25 | + $this->view->assign("sendStuList", $this->model->getSendStuList()); | ||
26 | + } | ||
27 | + | ||
28 | + public function import() | ||
29 | + { | ||
30 | + parent::import(); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 | ||
35 | + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 | ||
36 | + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 | ||
37 | + */ | ||
38 | + | ||
39 | + | ||
40 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 工单分类 | ||
9 | + * | ||
10 | + * @icon fa fa-circle-o | ||
11 | + */ | ||
12 | +class Ordertype extends Backend | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * Ordertype模型对象 | ||
17 | + * @var \app\admin\model\agent\Ordertype | ||
18 | + */ | ||
19 | + protected $model = null; | ||
20 | + | ||
21 | + public function _initialize() | ||
22 | + { | ||
23 | + parent::_initialize(); | ||
24 | + $this->model = new \app\admin\model\agent\Ordertype; | ||
25 | + | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
29 | + * 查看 | ||
30 | + */ | ||
31 | + public function index() | ||
32 | + { | ||
33 | + //当前是否为关联查询 | ||
34 | + $this->relationSearch = true; | ||
35 | + //设置过滤方法 | ||
36 | + $this->request->filter(['strip_tags', 'trim']); | ||
37 | + if ($this->request->isAjax()) { | ||
38 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
39 | + if ($this->request->request('keyField')) { | ||
40 | + return $this->selectpage(); | ||
41 | + } | ||
42 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
43 | + | ||
44 | + $list = $this->model | ||
45 | + ->where($where) | ||
46 | + ->where('siteswitch!=3') | ||
47 | + ->order('id', 'asc') | ||
48 | + ->paginate($limit); | ||
49 | + foreach ($list as $row) { | ||
50 | + $row->visible(['id', 'title', 'icon_image', 'weigh', 'siteswitch', 'price']); | ||
51 | + } | ||
52 | + $result = array("total" => $list->total(), "rows" => $list->items()); | ||
53 | + | ||
54 | + return json($result); | ||
55 | + } | ||
56 | + return $this->view->fetch(); | ||
57 | + } | ||
58 | + | ||
59 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * | ||
9 | + * | ||
10 | + * @icon fa fa-circle-o | ||
11 | + */ | ||
12 | +class Ordertypeprocess extends Backend | ||
13 | +{ | ||
14 | + | ||
15 | + /** | ||
16 | + * Ordertypeprocess模型对象 | ||
17 | + * @var \app\admin\model\agent\Ordertypeprocess | ||
18 | + */ | ||
19 | + protected $model = null; | ||
20 | + | ||
21 | + public function _initialize() | ||
22 | + { | ||
23 | + parent::_initialize(); | ||
24 | + $this->model = new \app\admin\model\agent\Ordertypeprocess; | ||
25 | + | ||
26 | + } | ||
27 | + | ||
28 | + public function import() | ||
29 | + { | ||
30 | + parent::import(); | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | + | ||
35 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 企业年费缴纳管理 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Paymentlogs extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Paymentlogs模型对象 | ||
18 | + * @var \app\admin\model\agent\Paymentlogs | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Paymentlogs; | ||
26 | + $agt_ids = $this->request->param('ids', 0); | ||
27 | + if ($agt_ids > 0) { | ||
28 | + $ginfo = Db::name('agent_list') | ||
29 | + ->where(['id' => $agt_ids]) | ||
30 | + ->find(); | ||
31 | + } else { | ||
32 | + $ginfo = []; | ||
33 | + } | ||
34 | + $this->view->assign('ginfo', $ginfo); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 查看 | ||
39 | + */ | ||
40 | + public function index() | ||
41 | + { | ||
42 | + //当前是否为关联查询 | ||
43 | + $this->relationSearch = true; | ||
44 | + //设置过滤方法 | ||
45 | + $this->request->filter(['strip_tags', 'trim']); | ||
46 | + if ($this->request->isAjax()) { | ||
47 | + $ids = $this->request->param('ids', 0); | ||
48 | + if ($ids > 0) { | ||
49 | + $wh['agent_list_id'] = ['=', $ids]; | ||
50 | + } else { | ||
51 | + $wh = ' 1=1 '; | ||
52 | + } | ||
53 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
54 | + if ($this->request->request('keyField')) { | ||
55 | + return $this->selectpage(); | ||
56 | + } | ||
57 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
58 | + | ||
59 | + $list = $this->model | ||
60 | + ->with(['agentlist']) | ||
61 | + ->where($where) | ||
62 | + ->where($wh) | ||
63 | + ->order($sort, $order) | ||
64 | + ->paginate($limit); | ||
65 | + | ||
66 | + foreach ($list as $row) { | ||
67 | + $row->visible(['id', 'agent_list_id', 'pay_price', 'createtime', 'start_pay_time', 'end_pay_time', 'stu_msg']); | ||
68 | + $row->visible(['agentlist']); | ||
69 | + $row->getRelation('agentlist')->visible(['agent_name']); | ||
70 | + } | ||
71 | + $rows = $list->items(); | ||
72 | + foreach ($rows as $kk => $vv) { | ||
73 | + //判断是否过期 | ||
74 | + $nowtime = time(); | ||
75 | + if ($nowtime > $vv['end_pay_time']) { | ||
76 | + $rows[$kk]['stu_msg'] = '已过期'; | ||
77 | + } else { | ||
78 | + $rows[$kk]['stu_msg'] = '有效'; | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
83 | + | ||
84 | + return json($result); | ||
85 | + } | ||
86 | + return $this->view->fetch(); | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * 添加 | ||
91 | + */ | ||
92 | + public function add() | ||
93 | + { | ||
94 | + if ($this->request->isPost()) { | ||
95 | + $params = $this->request->post("row/a"); | ||
96 | + if ($params) { | ||
97 | + $params = $this->preExcludeFields($params); | ||
98 | + $params['admin_id'] = $this->auth->id; | ||
99 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
100 | + $params[$this->dataLimitField] = $this->auth->id; | ||
101 | + } | ||
102 | + $result = false; | ||
103 | + Db::startTrans(); | ||
104 | + try { | ||
105 | + //是否采用模型验证 | ||
106 | + if ($this->modelValidate) { | ||
107 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
108 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
109 | + $this->model->validateFailException(true)->validate($validate); | ||
110 | + } | ||
111 | + $result = $this->model->allowField(true)->save($params); | ||
112 | + //处理企业支付时间,更新企业表支付结束时间 | ||
113 | + $agentpay['start_pay_time'] = strtotime($params['start_pay_time']); | ||
114 | + $agentpay['end_pay_time'] = strtotime($params['end_pay_time']); | ||
115 | + $agentpay['pay_stu'] = 1; | ||
116 | + $agentpay['updatetime'] = time(); | ||
117 | + Db::name('agent_list')->where(['id' => $params['agent_list_id']])->update($agentpay); | ||
118 | + Db::commit(); | ||
119 | + } catch (ValidateException $e) { | ||
120 | + Db::rollback(); | ||
121 | + $this->error($e->getMessage()); | ||
122 | + } catch (PDOException $e) { | ||
123 | + Db::rollback(); | ||
124 | + $this->error($e->getMessage()); | ||
125 | + } catch (Exception $e) { | ||
126 | + Db::rollback(); | ||
127 | + $this->error($e->getMessage()); | ||
128 | + } | ||
129 | + if ($result !== false) { | ||
130 | + $this->success(); | ||
131 | + } else { | ||
132 | + $this->error(__('No rows were inserted')); | ||
133 | + } | ||
134 | + } | ||
135 | + $this->error(__('Parameter %s can not be empty', '')); | ||
136 | + } | ||
137 | + return $this->view->fetch(); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * 编辑 | ||
142 | + */ | ||
143 | + public function edit($ids = null) | ||
144 | + { | ||
145 | + $row = $this->model->get($ids); | ||
146 | + if (!$row) { | ||
147 | + $this->error(__('No Results were found')); | ||
148 | + } | ||
149 | + $adminIds = $this->getDataLimitAdminIds(); | ||
150 | + if (is_array($adminIds)) { | ||
151 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
152 | + $this->error(__('You have no permission')); | ||
153 | + } | ||
154 | + } | ||
155 | + if ($this->request->isPost()) { | ||
156 | + $params = $this->request->post("row/a"); | ||
157 | + if ($params) { | ||
158 | + $params = $this->preExcludeFields($params); | ||
159 | + | ||
160 | + $result = false; | ||
161 | + Db::startTrans(); | ||
162 | + try { | ||
163 | + //是否采用模型验证 | ||
164 | + if ($this->modelValidate) { | ||
165 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
166 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
167 | + $row->validateFailException(true)->validate($validate); | ||
168 | + } | ||
169 | + | ||
170 | + $result = $row->allowField(true)->save($params); | ||
171 | + | ||
172 | + //处理企业支付时间,更新企业表支付结束时间 | ||
173 | + $agentpay['start_pay_time'] = strtotime($params['start_pay_time']); | ||
174 | + $agentpay['end_pay_time'] = strtotime($params['end_pay_time']); | ||
175 | + $agentpay['pay_stu'] = 1; | ||
176 | + $agentpay['updatetime'] = time(); | ||
177 | + Db::name('agent_list')->where(['id' => $params['agent_list_id']])->update($agentpay); | ||
178 | + | ||
179 | + Db::commit(); | ||
180 | + } catch (ValidateException $e) { | ||
181 | + Db::rollback(); | ||
182 | + $this->error($e->getMessage()); | ||
183 | + } catch (PDOException $e) { | ||
184 | + Db::rollback(); | ||
185 | + $this->error($e->getMessage()); | ||
186 | + } catch (Exception $e) { | ||
187 | + Db::rollback(); | ||
188 | + $this->error($e->getMessage()); | ||
189 | + } | ||
190 | + if ($result !== false) { | ||
191 | + $this->success(); | ||
192 | + } else { | ||
193 | + $this->error(__('No rows were updated')); | ||
194 | + } | ||
195 | + } | ||
196 | + $this->error(__('Parameter %s can not be empty', '')); | ||
197 | + } | ||
198 | + $this->view->assign("row", $row); | ||
199 | + return $this->view->fetch(); | ||
200 | + } | ||
201 | + | ||
202 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 购房售房人信息 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Payusers extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Payusers模型对象 | ||
18 | + * @var \app\admin\model\agent\Payusers | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Payusers; | ||
26 | + $this->view->assign("isnaturalpersonList", $this->model->getIsnaturalpersonList()); | ||
27 | + $this->view->assign("typeList", $this->model->getTypeList()); | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * 查看 | ||
32 | + */ | ||
33 | + public function index() | ||
34 | + { | ||
35 | + //当前是否为关联查询 | ||
36 | + $this->relationSearch = true; | ||
37 | + //设置过滤方法 | ||
38 | + $this->request->filter(['strip_tags', 'trim']); | ||
39 | + if ($this->request->isAjax()) { | ||
40 | + $ids = $this->request->param('ids', 0); | ||
41 | + if ($ids > 0) { | ||
42 | + $wh['agent_order_id'] = ['=', $ids]; | ||
43 | + } else { | ||
44 | + $wh = ' 1=1 '; | ||
45 | + } | ||
46 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
47 | + if ($this->request->request('keyField')) { | ||
48 | + return $this->selectpage(); | ||
49 | + } | ||
50 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
51 | + | ||
52 | + $list = $this->model | ||
53 | + ->where($where) | ||
54 | + ->where($wh) | ||
55 | + ->order('id','asc') | ||
56 | + ->paginate($limit); | ||
57 | + | ||
58 | + $rows = $list->items(); | ||
59 | + | ||
60 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
61 | + | ||
62 | + return json($result); | ||
63 | + } | ||
64 | + return $this->view->fetch(); | ||
65 | + } | ||
66 | + | ||
67 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\agent; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 一网通办人员管理 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Usermobile extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * Usermobile模型对象 | ||
18 | + * @var \app\admin\model\agent\Usermobile | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\agent\Usermobile; | ||
26 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
27 | + } | ||
28 | + | ||
29 | + public function import() | ||
30 | + { | ||
31 | + parent::import(); | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * 查看 | ||
36 | + */ | ||
37 | + public function index() | ||
38 | + { | ||
39 | + //当前是否为关联查询 | ||
40 | + $this->relationSearch = true; | ||
41 | + //设置过滤方法 | ||
42 | + $this->request->filter(['strip_tags', 'trim']); | ||
43 | + if ($this->request->isAjax()) { | ||
44 | + | ||
45 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
46 | + if ($this->request->request('keyField')) { | ||
47 | + return $this->selectpage(); | ||
48 | + } | ||
49 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
50 | + $a = []; | ||
51 | + $b = (json_decode((request()->param())['filter'],true))['status']; | ||
52 | + if($b === '1'){ | ||
53 | + | ||
54 | + }else{ | ||
55 | + $a['user_id'] = ['<>','']; | ||
56 | + } | ||
57 | + | ||
58 | + $list = $this->model | ||
59 | + ->where($where) | ||
60 | + ->where($a) | ||
61 | + ->order('id', 'desc') | ||
62 | + ->paginate($limit); | ||
63 | + | ||
64 | + $rows = $list->items(); | ||
65 | + foreach ($rows as $kk => $vv) { | ||
66 | + //关联经纪人信息 | ||
67 | + $agent = Db::name('agent_users') | ||
68 | + ->where(['jjr_mobile' => $vv['catname']]) | ||
69 | + ->find(); | ||
70 | + $rows[$kk]['agent_user'] = '-'; | ||
71 | + $rows[$kk]['userno'] = '-'; | ||
72 | + if (empty($agent)) { | ||
73 | + $rows[$kk]['agent_stu'] = '未注册'; | ||
74 | + } | ||
75 | + if ($agent['jjr_agent_stu'] == '0') { | ||
76 | + $rows[$kk]['agent_user'] = $agent['jjr_name']; | ||
77 | + $rows[$kk]['userno'] = $agent['userno']; | ||
78 | + $rows[$kk]['agent_stu'] = '未审核'; | ||
79 | + } | ||
80 | + if ($agent['jjr_agent_stu'] == '1') { | ||
81 | + $rows[$kk]['agent_user'] = $agent['jjr_name']; | ||
82 | + $rows[$kk]['userno'] = $agent['userno']; | ||
83 | + $rows[$kk]['agent_stu'] = '审核通过'; | ||
84 | + } | ||
85 | + if ($agent['jjr_agent_stu'] == '2') { | ||
86 | + $rows[$kk]['agent_user'] = $agent['jjr_name']; | ||
87 | + $rows[$kk]['userno'] = $agent['userno']; | ||
88 | + $rows[$kk]['agent_stu'] = '不通过'; | ||
89 | + } | ||
90 | + if ($agent['jjr_agent_stu'] == '3') { | ||
91 | + $rows[$kk]['agent_user'] = $agent['jjr_name']; | ||
92 | + $rows[$kk]['userno'] = $agent['userno']; | ||
93 | + $rows[$kk]['agent_stu'] = '离职'; | ||
94 | + } | ||
95 | + if ($agent['jjr_agent_stu'] == '4') { | ||
96 | + $rows[$kk]['agent_user'] = $agent['jjr_name']; | ||
97 | + $rows[$kk]['userno'] = $agent['userno']; | ||
98 | + $rows[$kk]['agent_stu'] = '非正常离职'; | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + $result = array("total" => $list->total(), "rows" => $rows); | ||
103 | + | ||
104 | + return json($result); | ||
105 | + } | ||
106 | + return $this->view->fetch(); | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * 添加 | ||
111 | + */ | ||
112 | + public function add() | ||
113 | + { | ||
114 | + if ($this->request->isPost()) { | ||
115 | + $params = $this->request->post("row/a"); | ||
116 | + if ($params) { | ||
117 | + $params = $this->preExcludeFields($params); | ||
118 | + //判断手机号码格式 | ||
119 | + if (!preg_match('/^1[3456789]\d{9}$/ims', $params['catname'])) { | ||
120 | + $this->error('手机号码格式不正确'); | ||
121 | + } | ||
122 | + //判断手机号码是否重复 | ||
123 | + $cksrs = Db::name('agent_user_mobile') | ||
124 | + ->where(['catname' => $params['catname']]) | ||
125 | + ->find(); | ||
126 | + if (!empty($cksrs)) { | ||
127 | + $this->error('手机号码已存在'); | ||
128 | + } | ||
129 | + | ||
130 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
131 | + $params[$this->dataLimitField] = $this->auth->id; | ||
132 | + } | ||
133 | + $result = false; | ||
134 | + //关联经纪人信息 | ||
135 | + $agent = Db::name('agent_users') | ||
136 | + ->where(['jjr_mobile' => $params['catname']]) | ||
137 | + ->find(); | ||
138 | + $params['user_id'] = $agent['user_id']; | ||
139 | + $params['jjr_name'] = $agent['jjr_name']; | ||
140 | + $params['userno'] = $agent['userno']; | ||
141 | + Db::startTrans(); | ||
142 | + try { | ||
143 | + //是否采用模型验证 | ||
144 | + if ($this->modelValidate) { | ||
145 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
146 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
147 | + $this->model->validateFailException(true)->validate($validate); | ||
148 | + } | ||
149 | + $result = $this->model->allowField(true)->save($params); | ||
150 | + | ||
151 | + | ||
152 | + Db::commit(); | ||
153 | + } catch (ValidateException $e) { | ||
154 | + Db::rollback(); | ||
155 | + $this->error($e->getMessage()); | ||
156 | + } catch (PDOException $e) { | ||
157 | + Db::rollback(); | ||
158 | + $this->error($e->getMessage()); | ||
159 | + } catch (Exception $e) { | ||
160 | + Db::rollback(); | ||
161 | + $this->error($e->getMessage()); | ||
162 | + } | ||
163 | + if ($result !== false) { | ||
164 | + | ||
165 | + $this->success(); | ||
166 | + } else { | ||
167 | + $this->error(__('No rows were inserted')); | ||
168 | + } | ||
169 | + } | ||
170 | + $this->error(__('Parameter %s can not be empty', '')); | ||
171 | + } | ||
172 | + return $this->view->fetch(); | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * 编辑 | ||
177 | + */ | ||
178 | + public function edit($ids = null) | ||
179 | + { | ||
180 | + $row = $this->model->get($ids); | ||
181 | + if (!$row) { | ||
182 | + $this->error(__('No Results were found')); | ||
183 | + } | ||
184 | + $adminIds = $this->getDataLimitAdminIds(); | ||
185 | + if (is_array($adminIds)) { | ||
186 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
187 | + $this->error(__('You have no permission')); | ||
188 | + } | ||
189 | + } | ||
190 | + if ($this->request->isPost()) { | ||
191 | + $params = $this->request->post("row/a"); | ||
192 | + if ($params) { | ||
193 | + $params = $this->preExcludeFields($params); | ||
194 | + //判断手机号码格式 | ||
195 | + if (!preg_match('/^1[3456789]\d{9}$/ims', $params['catname'])) { | ||
196 | + $this->error('手机号码格式不正确'); | ||
197 | + } | ||
198 | + //判断手机号码是否重复 | ||
199 | + $wh['id'] = ['neq', $row['id']]; | ||
200 | + $cksrs = Db::name('agent_user_mobile') | ||
201 | + ->where(['catname' => $params['catname']]) | ||
202 | + ->where($wh) | ||
203 | + ->find(); | ||
204 | + if (!empty($cksrs)) { | ||
205 | + $this->error('手机号码已存在'); | ||
206 | + } | ||
207 | + $result = false; | ||
208 | + //关联经纪人信息 | ||
209 | + $agent = Db::name('agent_users') | ||
210 | + ->where(['jjr_mobile' => $params['catname']]) | ||
211 | + ->find(); | ||
212 | + $params['user_id'] = $agent['user_id']; | ||
213 | + $params['jjr_name'] = $agent['jjr_name']; | ||
214 | + $params['userno'] = $agent['userno']; | ||
215 | + Db::startTrans(); | ||
216 | + try { | ||
217 | + //是否采用模型验证 | ||
218 | + if ($this->modelValidate) { | ||
219 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
220 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
221 | + $row->validateFailException(true)->validate($validate); | ||
222 | + } | ||
223 | + | ||
224 | + $result = $row->allowField(true)->save($params); | ||
225 | + Db::commit(); | ||
226 | + } catch (ValidateException $e) { | ||
227 | + Db::rollback(); | ||
228 | + $this->error($e->getMessage()); | ||
229 | + } catch (PDOException $e) { | ||
230 | + Db::rollback(); | ||
231 | + $this->error($e->getMessage()); | ||
232 | + } catch (Exception $e) { | ||
233 | + Db::rollback(); | ||
234 | + $this->error($e->getMessage()); | ||
235 | + } | ||
236 | + if ($result !== false) { | ||
237 | + $this->success(); | ||
238 | + } else { | ||
239 | + $this->error(__('No rows were updated')); | ||
240 | + } | ||
241 | + } | ||
242 | + $this->error(__('Parameter %s can not be empty', '')); | ||
243 | + } | ||
244 | + $this->view->assign("row", $row); | ||
245 | + return $this->view->fetch(); | ||
246 | + } | ||
247 | + | ||
248 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\wechat; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use app\admin\model\WechatResponse; | ||
7 | + | ||
8 | +/** | ||
9 | + * 微信自动回复管理 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class Autoreply extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + protected $model = null; | ||
17 | + protected $noNeedRight = ['check_text_unique']; | ||
18 | + | ||
19 | + public function _initialize() | ||
20 | + { | ||
21 | + parent::_initialize(); | ||
22 | + $this->model = model('WechatAutoreply'); | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * 编辑 | ||
27 | + */ | ||
28 | + public function edit($ids = null) | ||
29 | + { | ||
30 | + $row = $this->model->get(['id' => $ids]); | ||
31 | + if (!$row) { | ||
32 | + $this->error(__('No Results were found')); | ||
33 | + } | ||
34 | + if ($this->request->isPost()) { | ||
35 | + $params = $this->request->post("row/a"); | ||
36 | + if ($params) { | ||
37 | + $row->save($params); | ||
38 | + $this->success(); | ||
39 | + } | ||
40 | + $this->error(); | ||
41 | + } | ||
42 | + $response = WechatResponse::get(['eventkey' => $row['eventkey']]); | ||
43 | + $this->view->assign("response", $response); | ||
44 | + $this->view->assign("row", $row); | ||
45 | + return $this->view->fetch(); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * 判断文本是否唯一 | ||
50 | + * @internal | ||
51 | + */ | ||
52 | + public function check_text_unique() | ||
53 | + { | ||
54 | + $row = $this->request->post("row/a"); | ||
55 | + $except = $this->request->post("except"); | ||
56 | + $text = isset($row['text']) ? $row['text'] : ''; | ||
57 | + if ($this->model->where('text', $text)->where(function ($query) use ($except) { | ||
58 | + if ($except) { | ||
59 | + $query->where('text', '<>', $except); | ||
60 | + } | ||
61 | + })->count() == 0) { | ||
62 | + $this->success(); | ||
63 | + } else { | ||
64 | + $this->error(__('Text already exists')); | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | +} |
-
请 注册 或 登录 后发表评论