|
|
@@ -19,6 +19,157 @@ use think\Db;
|
|
|
class SalesController extends AdminBaseController
|
|
|
{
|
|
|
/**
|
|
|
+ * 查询已分配资源
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function search(){
|
|
|
+ $content = hook_one('admin_sales_search_view');
|
|
|
+
|
|
|
+ if (!empty($content)) {
|
|
|
+ return $content;
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = input();
|
|
|
+ $params['sort'] = isset($params['sort'])? $params['sort'] : 0;
|
|
|
+ $params['sort_type'] = isset($params['sort_type'])? $params['sort_type'] : 'desc';
|
|
|
+ $sort = $params['sort']==1? "p.create_time {$params['sort_type']}" : ($params['sort']==2? "p.expire_at {$params['sort_type']}" : ($params['sort'] == 4? "u.create_time {$params['sort_type']}" : ($params['sort'] == 5? "u.last_login_time {$params['sort_type']}" :"p.create_time {$params['sort_type']}")));
|
|
|
+
|
|
|
+ $list = PoolModel::alias('p')
|
|
|
+ ->leftJoin('user u','p.user_id=u.id')
|
|
|
+ ->leftJoin('user s','s.id=p.sale_uid')
|
|
|
+ ->leftJoin('user_profile up','up.userid=u.id')
|
|
|
+ ->where('p.sale_uid','>', 0)
|
|
|
+ ->where(function($query){
|
|
|
+ $query->where('p.expire_at','>=', date('Y-m-d H:i:s'))->whereOr('p.intention','in',[5])->whereOr('p.is_lock','=', 1);
|
|
|
+ })
|
|
|
+ ->where(['u.user_type'=> 2,'p.status'=>1,'p.type'=>0])
|
|
|
+ ->where(function($query) use($params){
|
|
|
+ $uid = isset($params['uid'])? $params['uid'] : 0;
|
|
|
+ if($uid){
|
|
|
+ $query->where(['u.id'=> $uid]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $nickname = isset($params['user_nickname'])? trim($params['user_nickname']) : '';
|
|
|
+ if($nickname){
|
|
|
+ $query->where('u.user_nickname','like',"{$nickname}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ $saleName = isset($params['sale_name'])? trim($params['sale_name']) : '';
|
|
|
+ if($saleName){
|
|
|
+ $query->where('s.user_login','like',"{$saleName}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ $realname = isset($params['real_name'])? trim($params['real_name']) : '';
|
|
|
+ if($realname){
|
|
|
+ $query->where('u.real_name','like',"{$realname}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ $mobile = isset($params['mobile'])? trim($params['mobile']) : '';
|
|
|
+ if($mobile){
|
|
|
+ $query->where('u.mobile','like',"{$mobile}%");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->field('p.id,p.user_id,u.openid,u.user_nickname,s.user_nickname as sale_name,s.user_login as sale_account,u.create_time as reg_time,u.last_login_time,u.real_name,u.avatar,u.vip_auth,u.vip_expire,u.user_status,u.mobile,up.graduate,up.age,up.married,u.birthday,u.sex,up.married,up.education,up.city,p.id as pool_id,p.intention,p.followup_num,p.agency,p.remark,p.create_time,p.follow_time,p.last_follow_time,p.expire_at')
|
|
|
+ ->order($sort);
|
|
|
+
|
|
|
+ $total = $list->count('p.id');
|
|
|
+ $list = $list->paginate(30, false, ['query' => request()->param()]);
|
|
|
+
|
|
|
+ // 获取分页显示
|
|
|
+ $page = $list->render();
|
|
|
+ $datas = $list ? $list->toArray() : [];
|
|
|
+ $tags = ['新分配','意向强','有意向','完全不考虑','已到店','已成交','待沟通','其他','无效资源'];
|
|
|
+ $agencys = ['无','今天需跟进','明天需跟进','到期未跟进','今天坠海','明天坠海','一礼拜后坠海','其他'];
|
|
|
+ if ($datas) {
|
|
|
+ $educations = config('weixin.educations');
|
|
|
+ $marrieds = config('weixin.marrieds');
|
|
|
+ foreach ($datas['data'] as $k => &$item) {
|
|
|
+ $item['avatar'] = $item['avatar']? cmf_get_image_preview_url($item['avatar']):'';
|
|
|
+
|
|
|
+ $isVip = isset($item['vip_auth'])? $item['vip_auth'] : 0;
|
|
|
+ $vipExpire = isset($item['vip_expire'])? $item['vip_expire'] : 0;
|
|
|
+ $item['is_vip'] = $isVip && time() < $vipExpire? 1 : 0;
|
|
|
+
|
|
|
+ // 是否充值和消费过
|
|
|
+ $item['is_recharge'] = UserRechargeLog::check($item['user_id'], 2);
|
|
|
+ $item['is_cost'] = AccountLog::check($item['user_id']);
|
|
|
+
|
|
|
+ $profile = [];
|
|
|
+ $birthday = isset($item['birthday'])? $item['birthday'] : 0;
|
|
|
+ $year = $birthday? date('Y', $birthday) : '';
|
|
|
+ if($year){
|
|
|
+ $profile[] = '<em class="red">'.(date('Y') - $year).'</em>岁(<em class="primary">'.$year.'</em>)';
|
|
|
+ }
|
|
|
+
|
|
|
+ $married = isset($item['married'])? $item['married'] : 0;
|
|
|
+ $marriedText = isset($marrieds[$married-1])? $marrieds[$married-1] : '';
|
|
|
+ if($marriedText){
|
|
|
+ $profile[] = $marriedText;
|
|
|
+ }
|
|
|
+
|
|
|
+ $education = isset($item['education'])? $item['education'] : 0;
|
|
|
+ $educationText = $education && isset($educations[$education])? $educations[$education] : '';
|
|
|
+ if($educationText){
|
|
|
+ $profile[] = $educationText;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($item['graduate']) && $item['graduate']){
|
|
|
+ $profile[] = $item['graduate'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $city = isset($item['city'])? $item['city'] : '';
|
|
|
+ if($city){
|
|
|
+ $profile[] = $city;
|
|
|
+ }
|
|
|
+
|
|
|
+ $item['profile_text'] = $profile? join(' ', $profile) : '';
|
|
|
+
|
|
|
+ $dayTime = strtotime(date('Y-m-d'));
|
|
|
+ $expireAt = isset($item['expire_at'])? $item['expire_at'] : '';
|
|
|
+ $time = strtotime($expireAt);
|
|
|
+ $expireTime = $expireAt? strtotime($expireAt) - time() : 0;
|
|
|
+ $day = $expireTime>0? intval($expireTime/(24*3600)) : 0;
|
|
|
+ $hour = $expireTime>0? intval(($expireTime-($day*24*3600))/3600) : 0;
|
|
|
+ $item['expire_text'] = $day? $day.'天'.$hour.'小时' : '已坠海';
|
|
|
+ $item['is_expired'] = 0;
|
|
|
+ if($time >= time() && $time < $dayTime + 86400){
|
|
|
+ $item['expire_text'] = '今天坠海';
|
|
|
+ $item['is_expired'] = 1;
|
|
|
+ }else if($time>=$dayTime+86400 && $time < $dayTime + 2 * 86400){
|
|
|
+ $item['expire_text'] = '明天坠海';
|
|
|
+ $item['is_expired'] = 1;
|
|
|
+ }else if($time>=$dayTime+7*86400 && $time < $dayTime + 8 * 86400){
|
|
|
+ $item['expire_text'] = '一礼拜后坠海';
|
|
|
+ }else if($expireTime <= 0 ){
|
|
|
+ $item['mobile'] = formatStr($item['mobile']);
|
|
|
+ $item['is_expired'] = 1;
|
|
|
+ $item['expire_text'] = '已坠海';
|
|
|
+ }
|
|
|
+
|
|
|
+ $intention = isset($item['intention'])? $item['intention'] : 0;
|
|
|
+ $item['intention_text'] = $intention>=0 && isset($tags[$intention])? $tags[$intention] : '';
|
|
|
+ $item['reg_time'] = $item['reg_time']? date('Y-m-d H:i:s', $item['reg_time']) : '';
|
|
|
+ $item['last_login_time'] = $item['last_login_time']? date('Y-m-d H:i:s', $item['last_login_time']) : '';
|
|
|
+
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assign('params', $params);
|
|
|
+ $this->assign('tags', $tags);
|
|
|
+ $this->assign('agencys', $agencys);
|
|
|
+ $this->assign('total', $total);
|
|
|
+ $this->assign('list', $datas['data']);
|
|
|
+ $this->assign('sales', UserModel::getSales());
|
|
|
+ $this->assign('page', $page);
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 我的资源库
|
|
|
* @return mixed
|
|
|
* @throws \think\db\exception\DataNotFoundException
|