初始化代码

This commit is contained in:
2025-12-22 14:32:54 +08:00
parent e27ab90d9f
commit d02b31a8b9
1459 changed files with 240973 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardAuth2Activity extends BaseModel
{
//定义表名
protected $name = 'longbing_cardauth2_activity';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardAuth2Article extends BaseModel
{
//定义表名
protected $name = 'longbing_cardauth2_article';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardBoss extends BaseModel
{
//定义表名
protected $name = 'longbing_card_boss';
protected static function init ()
{
//TODO:初始化内容
}
public function bosslist($where){
return $this->where($where)->value('boss');
}
}

View File

@@ -0,0 +1,460 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\dynamic\model\CardStatistics;
use think\Model;
class CardCount extends BaseModel
{
//定义表名
protected $name = 'longbing_card_count';
protected static function init ()
{
//TODO:初始化内容
}
public function getYesterdaylist($where){
$data = $this->where($where)
->whereDay('create_time','yesterday')
->field('to_uid as user_id,type,sign,count(to_uid) as number,uniacid')
->group('to_uid')
->order('create_time','desc')
->select()
->toArray();
if($data){
$stat = new CardStatistics();
foreach ($data as $key=>$val){
$data[$key]['create_time'] = strtotime("-1 day");
$data[$key]['table'] = 'CardCount';
// $whe['user_id'] = $val['to_uid'];
// $whe['type'] = $val['type'];
// $whe['sign'] = $val['sign'];
// $info = $stat->getUserid($whe);
// if($info){
// $stat->where($whe)->inc('number',$val['number'])->update();
// }else{
// $whe['number'] =$val['number'];
// $stat->addinfo($whe);
}
// }print_r(123);exit;
$stat->createRows($data);
}
return $data;
}
//昨日数据
public function getYesterday($where){
return $this->where($where)->whereDay('create_time','yesterday')->count();
}
//今日数据
public function gettoday($where){
return $this->where($where)->whereDay('create_time')->count();
}
//新增咨询
public function zxInfo($user_id,$where=[],$type=0){
if($type==1){
$de = '=';
}else{
$de = 'in';
}
$where1 = [
['to_uid',$de,$user_id],
['sign','=','copy'],
['type','=','8'],
$where
];
$where2 = [
['to_uid',$de,$user_id],
['sign','=','praise'],
['type','=','5'],
$where
];
$count = $this->where([array_filter($where1)])->whereor([array_filter($where2)])->count();
return $count;
}
public function getCount($where5){
$data = $this->where($where5)->count();
return $data;
}
public function radarList ( $where = [], $page = 1, $list_rows = 20 )
{
$data = self::where( $where )
->alias( 'a' )
->field( [ 'a.*','b.nickName as name']
)
->join( 'longbing_card_user b', 'a.user_id = b.id' )
->join( 'longbing_card_collection c', 'a.user_id = c.uid && a.to_uid = c.to_uid' )
->order( [ 'a.id' => 'desc' ] )
->paginate( [ 'list_rows' => $list_rows, 'page' => $page ]
)
->toArray();
// 查询手机号
// $tmpArr = [];
// foreach ( $data[ 'data' ] as $index => $item )
// {
// $data[ 'data' ][ $index ][ 'phone' ] = '';
// array_push( $tmpArr, $item[ 'user_id' ] );
// }
// if ( !empty( $tmpArr ) )
// {
// $tmpArr = array_unique( $tmpArr );
//
// $list = UserPhone::where( [ [ 'user_id', 'in', $tmpArr ] ] )
// ->field( [ 'user_id', 'phone' ] )
// ->select()
// ->toArray();
//
// $tmpArr = [];
// foreach ( $list as $index => $item )
// {
// $tmpArr[ $item[ 'user_id' ] ] = $item[ 'phone' ];
// }
// foreach ( $data[ 'data' ] as $index => $item )
// {
// if ( isset( $tmpArr[ $item[ 'user_id' ] ] ) )
// {
// $data[ 'data' ][ $index ][ 'phone' ] = $tmpArr[ $item[ 'user_id' ] ];
// }
// }
// }
if (!empty($data[ 'data' ]))
{
// 处理雷达展示日期
//$data[ 'data' ] = lbHandelRadarDate( $data[ 'data' ] );
// 处理用户来源
//$data[ 'data' ] = lbHandelRadarSource( $data[ 'data' ] );
// 处理雷达激励提醒文案
$data[ 'data' ] = lbHandelRadarMsg( $data[ 'data' ] );
}
return $data;
}
//兴趣占比
public function doPageBossInterest ($where,$uniacid)
{
$filter = [
['sign','=','copy'] , ['uniacid','=',$uniacid],$where,[ 'type', 'in', [ 6, 7 ,11] ]
];
$filter1 = [
['sign','=','view'] , [ 'type', '=', 6 ],['uniacid','=',$uniacid],$where
];
//// // 对公司感兴趣
$compony = $this->where([$filter])->whereor([$filter1])->count();
$filter2 = [
['sign','=','copy'] , ['uniacid','=',$uniacid],$where,[ 'type', '=', 8 ]
];
$where3 = [
['sign','=','view'] ,['uniacid','=',$uniacid],$where,[ 'type', 'in', [ 1, 2, 11, 15, 16, 17, 19, 20, 25, 26, 27, 28, 29, 30 ] ]
];
$where21 = [
['sign','=','praise'] , ['uniacid','=',$uniacid],$where, [ 'type', 'in', [ 5, 6, 7, 8 ] ]
];
$where31 = [
['sign','=','order'] ,['uniacid','=',$uniacid],$where
];
// 对产品感兴趣
$goods = $this->where([$filter2])->whereor([$where3])->whereor([$where21])->whereor([$where31])->count();
// 对员工感兴趣
$where4 = [
['sign','=','copy'],['uniacid','=',$uniacid],$where, [ 'type', 'in', [ 1, 2, 3, 4, 5, 9, 10 ] ]
];
$where5 = [
['sign','=','praise'],['uniacid','=',$uniacid],$where,[ 'type', 'in', [ 1, 2, 3, 4 ] ]
];
$staff = $this->where([$where4])->whereor([array_filter($where5)])->count();
$total = $compony + $goods + $staff;
$data = [
[
'data' => $compony,
'rate' => 0,
'name'=>'对公司感兴趣'
],
[
'data' => $goods,
'rate' => 0,
'name'=>'对产品感兴趣'
],
[
'data' => $staff,
'rate' => 0,
'name'=>'对我感兴趣'
],
];
if ( $total ) {
foreach ( $data as $k => $v ) {
$data[ $k ][ 'rate' ] = sprintf( "%.2f", $v[ 'data' ] / $total ) * 100;
}
}
return $data;
}
//活跃度0,1,2 $type 单个用户还是多个
// public function doPageActivity ($uid,$type=0)
// {
// if($type ==1){
// $str = 'in';
// $last = 7;
// }else{
// $str = '=';
// $last = 30;
// }
// //$forward = new CardForward();
// //$stat = new CardStatistics();
// $card_count = new CardCount();
// $data = [];
// $ss = [];
// for ( $i = 0; $i < $last; $i++ ) {
// $beginTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - $i, date( 'Y' ) );
// $endTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - $i + 1, date( 'Y' ) ) - 1;
// $date = date( 'm/d', $beginTime );
// $data[ $i ][ 'date' ] = $date;
// $data[ $i ][ 'beginTime' ] = $beginTime;
// $data[ $i ][ 'endTime' ] = $endTime;
//
//
//// $where1[] = [
//// ['user_id',$str,$uid],['table','=','forward'],['create_time','BETWEEN',[$beginTime,$endTime]]
//// ];
// // $count2 = $forward->forwardCount($where1);
//// $wherez = [['sign','=','praise'], ['type','=',4],['to_uid','=',$uid],['uniacid','=',$this->_uniacid],['create_time','BETWEEN',[$beginTime,$endTime]]];
//// $count2 =$card_count->getCount($wherez);
// //$count2 = $stat->getCustomerCount($where1);
// $card_message = new CardMessage();
//// $where2[] = [
//// ['user_id',$str,$uid],['table','=','message'],['create_time','BETWEEN',[$beginTime,$endTime]]
//// ];
// $where3 = [['status','=',1], ['deleted','=',0],['target_id',$str,$uid],['uniacid','=',$this->_uniacid],['create_time','BETWEEN',[$beginTime,$endTime]]];
// $count3 = $card_message->getCount($where3);
// //$count3 = $stat->getCustomerCount($where2);
//
// //$card_count = new CardCount();
// $where4 = [['sign','=','copy'],['to_uid',$str,$uid],['uniacid','=',$this->_uniacid],['create_time','BETWEEN',[$beginTime,$endTime]]];
//// $where3[] = [
//// ['user_id',$str,$uid],['create_time','BETWEEN',[$beginTime,$endTime],['sign','=','copy']]
//// ];
// $count4 = $card_count->getCount($where4);
//// $where3[] = [
//// ['user_id',$str,$uid],['create_time','BETWEEN',[$beginTime,$endTime],['sign','=','view']]
//// ];
// $where5 = [['sign','=','view'],['to_uid',$str,$uid],['uniacid','=',$this->_uniacid],['create_time','BETWEEN',[$beginTime,$endTime]]];
// $count5 = $card_count->getCount($where5);
// $where3[] = [
// ['user_id',$str,$uid],['create_time','BETWEEN',[$beginTime,$endTime],['sign','=','praise']]
// ];
// $where6 = [['sign','=','praise'],['to_uid',$str,$uid],['uniacid','=',$this->_uniacid],['create_time','BETWEEN',[$beginTime,$endTime]]];
// $count6 = $card_count->getCount($where6);
//
//// $count6 = $stat->getCustomerCount($where3);$count2 +
// $count = $count3 + $count4 + $count5 + $count6;
// $data[ $i ][ 'number' ] = $count;
// $ss[] = $count;
// }
// $arr = max($ss);
// if($arr ==0){
// $arr =5;
// }
// return ['max'=>$arr,'data'=>$data];
// }
public function active ( $staff_id, $uniacid,$type=0 )
{
if($type ==1){
$str = 'in';
// $last = 7;['uniacid'=>$uniacid],
}else{
$str = '=';
// $last = 30;
}
$data = [];
$lastday = date( 'Y/m/d' );
$number = self::where( [ [ 'to_uid',$str, $staff_id ], [ 'create_time', 'between',
[ strtotime( $lastday . ' 00:00:00' ), strtotime( $lastday . ' 23:59:59' ) ] ] ]
)
->count();
$data[] = [ 'date' => date( 'm/d' ), 'number' => $number ];
$max = $number;
for ( $i = 1; $i < 15; $i++ )
{
$start_time = strtotime( "$lastday -$i days" );
$md = date( 'm/d', $start_time );
$ymd = date( 'Y/m/d', $start_time );
$end_time = strtotime( $ymd . ' 23:59:59' );
$number = self::where( [ [ 'to_uid',$str, $staff_id ],
[ 'create_time', 'between', [ $start_time, $end_time ] ] ]
)
->count();
if ( $number > $max )
{
$max = $number;
}
$data[] = [ 'date' => $md, 'number' => $number ];
}
return [ 'data'=>$data, 'max'=>$max ];
}
public function getsss($staff_id,$uniacid,$type=0){
if($type==1){
$str = '=';
}else{
$str = 'in';
}
$data = [ 'max_number' => 0, 'total' => 0, 'data' => [] ];
//咨询产品
$count = self::where( [ [ 'sign', '=', 'copy' ], [ 'to_uid',$str, $staff_id ],
[ 'type', '=', 8 ],[ 'uniacid', '=', $uniacid ] ]
)
->count();
$data[ 'max_number' ] = $count;
$data[ 'total' ] += $count;
$data[ 'data' ][] = [ 'name' => '咨询产品', 'number' => $count ];
// 保存电话
$count = self::where( [ [ 'sign', '=', 'copy' ], [ 'to_uid', $str, $staff_id ],
[ 'type', '=', 1 ] ,[ 'uniacid', '=', $uniacid ]]
)
->count();
if ( $count > $data[ 'max_number' ] )
{
$data[ 'max_number' ] = $count;
}
$data[ 'total' ] += $count;
$data[ 'data' ][] = [ 'name' => '保存电话', 'number' => $count ];
// 拨打电话
$count = self::where( [ [ 'sign', '=', 'copy' ], [ 'to_uid', $str, $staff_id ],[ 'uniacid', '=', $uniacid ],
[ 'type', 'in', [ 2, 3, 11 ] ] ]
)
->count();
$count += self::where( [ [ 'sign', '=', 'praise' ], [ 'to_uid', $str, $staff_id ],[ 'uniacid', '=', $uniacid ],
[ 'type', '=', 7 ] ]
)
->count();
if ( $count > $data[ 'max_number' ] )
{
$data[ 'max_number' ] = $count;
}
$data[ 'total' ] += $count;
$data[ 'data' ][] = [ 'name' => '拨打电话', 'number' => $count ];
$view_base_filter = [
['to_uid', $str, $staff_id],
['sign', '=', 'view'],[ 'uniacid', '=', $uniacid ]
];
//浏览商城
$view_shop_filter = $view_base_filter;
$view_shop_filter[] = ['type' , '=' , 1];
$view_shop_number = self::where($view_shop_filter)->count();
$data['total'] += $view_shop_number;
$data['data'][] = ['name' => '浏览商城', 'number' => $view_shop_number];
//浏览商品
$view_goods_filter = $view_base_filter;
$view_goods_filter[] = ['type' , '=' , 2];
$view_goods_number = self::where($view_goods_filter)->count();
$data['total'] += $view_goods_number;
$data['data'][] = ['name' => '浏览商品', 'number' => $view_goods_number];
//查看官网
$view_official_web_filter = $view_base_filter;
$view_official_web_filter[] = ['type' , '=' , 6];
$view_official_web_number = self::where($view_official_web_filter)->count();
$data['total'] += $view_official_web_number;
$name = tabbarName(4,$uniacid);
$data['data'][] = ['name' =>!empty($name)?'查看'.$name: '查看官网', 'number' => $view_official_web_number];
//浏览动态
$view_timeline_filter = $view_base_filter;
$view_timeline_filter[] = ['type' , '=' , 3];
$view_timeline_number = self::where($view_timeline_filter)->count();
$data['total'] += $view_timeline_number;
$data['data'][] = ['name' => '浏览动态', 'number' => $view_timeline_number];
//点赞
$praise_filter = [
['to_uid', $str, $staff_id],[ 'uniacid', '=', $uniacid ],
['sign', '=', 'praise'],
['type', 'IN', [1, 3]]
];
$praise_number = self::where($praise_filter)->count();
$data['total'] += $praise_number;
$data['data'][] = ['name' => '点赞', 'number' => $praise_number];
//分享名片
$share_filter = [
['to_uid', $str, $staff_id],[ 'uniacid', '=', $uniacid ],
['sign', '=', 'praise'],
['type', '=', 4]
];
$share_number = self::where($share_filter)->count();
$data['total'] += $share_number;
$data['data'][] = ['name' => '分享', 'number' => $share_number];
//按number倒序
$sort_arr = [];
foreach ($data['data'] as $k => $v) {
$sort_arr[] = $v['number'];
}
array_multisort($sort_arr, SORT_DESC, $data['data']);
$data['max_number'] = $data['data'][0]['number'] ?? 0;
//计算rate
foreach ($data['data'] as $index => $item) {
if ($data['max_number'] == 0) {
$rate = 0;
} else {
$rate = $item['number'] / $data['max_number'] * 100;
}
$rate = sprintf("%.0f", $rate);
$data['data'][$index]['rate'] = $rate;
}
return $data;
}
public function getCountUser($where,$time){
$data = $this->alias('a')
->join( 'longbing_card_user_info b', 'a.to_uid = b.fans_id' )
->where($where)
->whereDay('a.create_time',$time)
->group('user_id')
->count();
return $data;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardCoupon extends BaseModel
{
//定义表名
protected $name = 'longbing_card_coupon';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardCouponRecord extends BaseModel
{
//定义表名
protected $name = 'longbing_card_coupon_record';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\member\model\Member;
use app\shop\model\AdminShopSpePrice;
use app\shop\model\IndexUserInfo;
use app\shop\model\IndexUserShop;
use think\facade\Db;
use think\Model;
class CardExtension extends BaseModel
{
//定义表名
protected $name = 'longbing_card_extension';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 名片的标签列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function cardExtensionList ( $staff_id, $uniacid )
{
$user_model = new IndexUserInfo();
$company_id = $user_model->getCompanyId(['fans_id'=>$staff_id],$uniacid);
$member_model= new Member();
$arr = [];
if($member_model->getAuth($uniacid)==true){
$arr[] = ['b.is_member','=',0];
}
$dis[] = ['d.company_id','=',$company_id];
$dis[] = ['b.public_goods','=',1];
$config = longbingGetAppConfig($uniacid);
//自选
if($config['myshop_switch']==1){
$user_shop = new IndexUserShop();
$my_goods = $user_shop->MyGoodList(['user_id'=>$staff_id,'uniacid'=>$uniacid]);
$arrs[] = ['a.id','in',$my_goods];
}else{
$arrs[] = ['a.index_show', '=', 1];
}
$data = self::where( [ [ 'a.user_id', '=', $staff_id ], [ 'a.status', '=', 1 ], [ 'b.status', '=', 1 ], [ 'a.uniacid', '=', $uniacid ] ] )
->where($arr)
->alias( 'a' )
->field( [ 'a.id as e_id','b.id', 'b.name', 'b.cover', 'b.price', 'b.status', 'b.unit', 'b.recommend', 'b.is_collage' ]
)
->where(function ($query) use ($dis){
$query->whereOr($dis);
})
->join('longbing_card_goods b', 'a.goods_id = b.id')
->join('longbing_card_user_info c','a.user_id = c.fans_id')
->join('longbing_card_company_goods d' ,'c.company_id = d.company_id and a.goods_id = d.goods_id','left')
// ->order( [ 'a.id' => 'desc' ] )
->order('a.status desc,b.recommend desc,b.top desc,b.id desc,b.update_time desc')
->select()
->toArray();
if($data){
$spe_price = new AdminShopSpePrice();
foreach ($data as $key=>$val){
$o_dis = [];
$o_dis[] = ['status','=',1];
$o_dis[] = ['goods_id','=',$val['id']];
$data[$key]['price_text'] = $spe_price->where($o_dis)->min('price');
$o_dis[] = ['original_price','<>',0];
$data[$key]['original_price'] = $spe_price->where($o_dis)->min('original_price');
}
}
$data = transImagesOne($data, ['cover']);
$data = formatNumberPrice($data);
return $data;
}
public function getlist($dis){
$data = $this
->alias('a')
->join('longbing_card_user_info b','a.user_id = b.fans_id')
->join('longbing_card_company_goods c' ,'b.company_id = c.company_id and a.goods_id = c.goods_id')
->join('longbing_card_goods d' ,'a.goods_id = d.id and d.status = 1')
->where($dis)
->field(['a.*'])
->order('a.create_time','desc')
->select()
->toArray();
return $data;
}
public function getCount($where){
return $this->where($where)->count();
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardFormId extends BaseModel
{
//定义表名
protected $name = 'longbing_card_form_id';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\dynamic\model\CardStatistics;
use think\Model;
class CardForward extends BaseModel
{
//定义表名
protected $name = 'longbing_card_forward';
protected static function init ()
{
//TODO:初始化内容
}
public function getCount($where){
$data = $this
->field('staff_id as user_id,count(staff_id) as number,uniacid')
->whereDay('create_time','yesterday')
->group('staff_id')
->where($where)->select()->toArray();
if($data){
foreach ($data as $key=>$val){
$data[$key]['table'] = 'forward';
$data[$key]['create_time'] = strtotime("-1 day");
}
$stat = new CardStatistics();
$stat->createRows($data);
}
return $data;
}
public function getYesterday($where){
return $this->where($where)->whereDay('create_time','yesterday')->count();
}
public function forwardCount($where4){
return $this->where($where4)->count();
}
}

147
app/card/model/CardJob.php Normal file
View File

@@ -0,0 +1,147 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardJob extends BaseModel
{
//定义表名
protected $name = 'longbing_card_job';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 根据员工获取工具列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getListByUser ( $card_id = 0, $uniacid )
{
$list = self::where( [ [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1 ] ] )
->field( [ 'id', 'name' ] )
->order( 'top', 'desc' )
->select()
->toArray();
if ( !$list )
{
$list = $this->initCardJob( $uniacid );
}
foreach ( $list as $index => $item )
{
$list[ $index ][ 'selected' ] = 0;
if ( isset( $item[ 'id' ] ) && $item[ 'id' ] == $card_id )
{
$list[ $index ][ 'selected' ] = 1;
}
}
return $list;
}
/**
* @Purpose: 初始化名片样式
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function initCardJob ( $uniacid )
{
$data = [ [ 'name' => '首席服务官', 'uniacid' => $uniacid ] ];
$result = self::createRows( $data );
return $result->toArray();
}
// public function getJob($filter)
// {
// $result = $this->where($filter)->find();
// if(!empty($result)) $result = $result->toArray();
// return $result;
// }
/**
* @Purpose: 创建职位
*
* @Author: yangqi
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function createJob($data){
$data['create_time'] = time();
$result = $this->save($data);
return !empty($result);
}
/**
* @Purpose: 更新职位
*
* @Author: yangqi
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function updateJob($filter ,$data){
$data['update_time'] = time();
$result = $this->where($filter)->update($data);
return !empty($result);
}
/**
* @Purpose: 获取职位列表
*
* @Author: yangqi
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function listJob($filter ,$page_config = ['page' => 1 ,'page_count' => 20 ]){
$result = $this->where($filter)
->order('top desc , id desc')
->page($page_config['page'] ,$page_config['page_count'])
->select();
if(!empty($result)) $result = $result->toArray();
return $result;
}
/**
* @Purpose: 获取职位详情
*
* @Author: yangqi
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getJob($filter){
$result = $this->where($filter)->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
/**
* @Purpose: 删除职位信息
*
* @Author: yangqi
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function delJob($filter){
$result = $this->updateJob($filter ,['status' => -1 ,'update_time' => time()]);
return !empty($result);
}
/**
* @Purpose: 获取职位总数
*
* @Author: yangqi
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getJobCount($filter){
$result = $this->where($filter)->count();
return $result;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardLabel extends BaseModel
{
//定义表名
protected $name = 'longbing_card_label';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\dynamic\model\CardStatistics;
class CardMessage extends BaseModel
{
//定义表名
protected $name = 'longbing_card_message';
protected static function init ()
{
//TODO:初始化内容
}
public function getCount($where){
return $this->where($where)->count();
}
// public function getCountlist($where){
// $data = $this
// ->field('target_id as user_id,count(target_id) as number,uniacid')
// ->whereDay('create_time','yesterday')
// ->group('target_id')
// ->where($where)->select()->toArray();
// if($data){
// foreach ($data as $key=>$val){
// $data[$key]['table'] = 'message';
// $data[$key]['create_time'] = strtotime("-1 day");
// }
// $stat = new CardStatistics();
// $stat->createRows($data);
// }
// return $data;
// }
}

View File

@@ -0,0 +1,63 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardTags extends BaseModel
{
//定义表名
protected $name = 'longbing_card_tags';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 名片的标签列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function cardTagList ( $staff_id, $client_id, $uniacid )
{
$data = self::where( [ [ 'user_id', '=', $staff_id ], [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1 ] ] )
->select()
->toArray();
foreach ( $data as $index => $item )
{
$data[ $index ][ 'thumbed' ] = 0;
$check = CardUserTags::where( [ [ 'tag_id', '=', $item[ 'id' ] ],
[ 'user_id', '=', $client_id ], [ 'uniacid', '=', $uniacid ],
[ 'status', '=', 1 ] ]
)
->count();
if ($check)
{
$data[ $index ][ 'thumbed' ] = 1;
}
}
return $data;
}
public function getTag($filter)
{
$result = $this->where($filter)->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
public function getTagCount($filter)
{
$count = $this->where($filter)->count();
return $count;
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardType extends BaseModel
{
//定义表名
protected $name = 'longbing_card_card_type';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 初始化名片样式
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function initCardType ( $uniacid )
{
$data = [ [ 'card_type' => 'cardType1', 'img' => 'https://retail.xiaochengxucms.com/1.png', 'uniacid' => $uniacid ],
[ 'card_type' => 'cardType4', 'img' => 'https://retail.xiaochengxucms.com/2.png', 'uniacid' => $uniacid ],
[ 'card_type' => 'cardType2', 'img' => 'https://retail.xiaochengxucms.com/4.png', 'uniacid' => $uniacid ],];
$result = self::createRows( $data );
return $result->toArray();
}
/**
* @Purpose: 初始化名片样式
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getCardTypeList ( $uniacid, $type = '' )
{
$list = self::where( [ [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1 ] ] )
->select()
->toArray();
foreach ( $list as $index => $item )
{
$list[$index]['selected'] = 0;
if ($item['card_type'] == $type)
{
$list[$index]['selected'] = 1;
}
}
return $list;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardUserLabel extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_label';
protected static function init ()
{
//TODO:初始化内容
}
public function getlist($where){
return $this->where($where)->group('user_id')->field('user_id,uniacid')->select()->toArray();
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class CardUserTags extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_tags';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\dynamic\model\CardShareGroup;
use think\Model;
class CardValue extends BaseModel
{
//定义表名
protected $name = 'longbing_card_value';
protected static function init ()
{
//TODO:初始化内容
}
public function getlist($where){
return $this->where($where)->order('update_time','desc')->find();
}
public function bossGetAiValue ( $id,$uniacid )
{
$value = [
'client' => 0, // 获客能力值
'charm' => 0, // 个人魅力值
'interaction' => 0, // 客户互动值
'product' => 0, // 产品推广值
'website' => 0, // 官网推广度
'active' => 0, // 销售主动性值
];
$check = $this->getlist([ 'staff_id' => $id ]);
if ( !$check || ( $check && time() - $check[ 'update_time' ] > 24 * 60 * 60 ) ) {
$colle = new Collection();
// 获客能力值
$client = $colle->getlistCount(['status' => 1, 'to_uid' => $id,]);
if ( $client > 0 ) {
$client -= 1;
}
$value[ 'client' ] = $client;
$card_count = new CardCount();
// 个人魅力值
$list1 = $card_count->getCount([ 'sign' => 'praise', 'type' => 1, 'to_uid' => $id ]);
$list2 = $card_count->getCount( [ 'sign' => 'praise', 'type' => 3, 'to_uid' => $id ]);
$list3 = $card_count->getCount([ 'sign' => 'copy', 'to_uid' => $id ]);
$count = $list1 + $list2+ $list3;
$value[ 'charm' ] = $count;
$card_message = new CardMessage();
// 客户互动值
$list1 = $card_message->getCount([ 'user_id' => $id ]);
$list2 = $card_message->getCount([ 'target_id' => $id ]);
$list3 = $card_count->getCount([ 'sign' => 'view', 'to_uid' => $id ]);
$count = $list1 + $list2 + $list3;
$value[ 'interaction' ] = $count;
$extension = new CardExtension();
$mark = new UserMark();
$forward = new CardForward();
$group = new CardShareGroup();
// 产品推广值
$list1 = $extension->getCount([ 'user_id' => $id, 'uniacid' => $uniacid ]);
$list2 = $mark->getCount([ 'staff_id' => $id, 'uniacid' => $uniacid, 'mark' => 2 ]);
$list3 = $forward->forwardCount([ 'staff_id' => $id, 'uniacid' => $uniacid, 'type' => 2 ]);
$where=[['user_id','=',$id],['uniacid','=',$uniacid], ['view_goods','<>',''] ];
$list4 = $group->getCount($where);
$count = $list1 + $list2 + $list3 + $list4;
$value[ 'product' ] = $count;
// 官网推广度
$list1 = $card_count->getCount([ 'sign' => 'view', 'type' => 6, 'to_uid' => $id ]);
$list2 = $forward->forwardCount([ 'staff_id' => $id, 'uniacid' => $uniacid, 'type' => 4 ]);
$count = $list1 + $list2;
$value[ 'website' ] = $count;
$follow = new UserFollow();
// 销售主动性值
$list1 = $card_message->getCount([ 'user_id' => $id ]);
$list2 = $card_message->getCount([ 'target_id' => $id ]);
$list3 = $follow->getCount([ 'staff_id' => $id ]);
$list4 = $mark->getCount([ 'staff_id' => $id ]);
$count = $list1 + $list2 + $list3+ $list4;
$value[ 'active' ] = $count;
$insertData = $value;
$insertData[ 'staff_id' ] = $id;
$time = time();
$insertData[ 'update_time' ] = $time;
$insertData[ 'uniacid' ] = $uniacid;
if ( !$check ) {
$insertData[ 'create_time' ] = $time;
$this->createRow($insertData);
} else {
$insertData[ 'update_time' ] = $time;
$this->upsave([ 'id' => $check[ 'id' ]],$insertData);
}
} else {
$value = [
'client' => $check[ 'client' ], // 获客能力值
'charm' => $check[ 'charm' ], // 个人魅力值
'interaction' => $check[ 'interaction' ], // 客户互动值
'product' => $check[ 'product' ], // 产品推广值
'website' => $check[ 'website' ], // 官网推广度
'active' => $check[ 'active' ], // 销售主动性值
];
}
$max=array_sum(array($value[ 'active' ],$value[ 'charm' ],$value[ 'client' ],$value[ 'interaction' ],$value[ 'product' ],$value[ 'website' ]));
$web_name = tabbarName(4,$uniacid);
$data = [
[
'name'=>'销售主动性值',
'number'=>$value[ 'active' ],
],
[
'name'=>!empty($web_name)?$web_name.'推广度':'官网推广度',
'number'=>$value[ 'website' ],
$bb[] = $value[ 'website' ]
],
[
'name'=>'产品推广值',
'number'=>$value[ 'product' ],
],
[
'name'=>'客户互动值',
'number'=>$value[ 'interaction' ],
],
[
'name'=>'获客能力值',
'number'=>$value[ 'client' ],
],
[
'name'=>'个人魅力值',
'number'=>$value[ 'charm' ],
],
];
return ['max'=>$max,'data'=>$data];
}
function bossAi ($user_list, $uniacid )
{
$max = [
0 => 0, // 销售主动性值
1 => 0, // 官网推广度
2 => 0, // 产品推广值
3 => 0, // 客户互动值
4 => 0, // 获客能力值
5 => 0, // 个人魅力值
];
$staff_list = User::where( [ [ 'uniacid', '=', $uniacid ], [ 'is_staff', '=', 1 ] ] )
->field( [ 'id', 'nickName' ] )
->where('id','in',$user_list)
->select()
->toArray();
foreach ( $staff_list as $k => $v )
{
$total = 0;
$value = $this->bossGetAiValue( $v[ 'id' ], $uniacid );
foreach ( $value['data'] as $k2 => $v2 )
{
if ( $v2[ 'number' ] > $max[ $k2 ] )
{
$max[ $k2 ] = $v2[ 'number' ];
}
$total += $v2[ 'number' ];
}
$staff_list[ $k ][ 'number' ] = $value['data'];
//$staff_list[ $k ][ 'total' ] = $total;
// $staff_list[ $k ][ 'info' ] = $info;
}
// // 二维数组排序
// array_multisort( array_column( $staff_list, 'total' ), SORT_DESC, $staff_list );
//
// $staff_list = array_splice( $staff_list, 0, 3 );
$data = ['max_data' => $max,'max_number'=>max($max) ];
return $data;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class ClientInfo extends BaseModel
{
//定义表名
protected $name = 'longbing_card_client_info';
protected static function init ()
{
//TODO:初始化内容
}
}

View File

@@ -0,0 +1,931 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\dynamic\model\CardShopOrder;
use app\dynamic\model\CardStatistics;
use app\dynamic\model\UserInfo;
use app\radar\model\RadarCount;
use think\facade\Db;
use think\Model;
class Collection extends BaseModel
{
//定义表名
protected $name = 'longbing_card_collection';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 绑定的员工列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function bindCardList ( $userId, $userInfo, $page = 1, $uniacid = 0 )
{
$page = intval( $page );
$page = $page ? $page : 1;
$data = self::alias( 'a' )
->join( 'longbing_card_user_info b', 'a.to_uid = b.fans_id' )
->join( 'longbing_card_job c', 'b.job_id = c.id', 'LEFT' )
->where( [ [ 'a.uniacid', '=', $uniacid ], [ 'a.uid', '=', $userId ], [ 'a.status', '=', 1 ],
[ 'b.is_staff', '=', 1 ], [ 'a.to_uid', '<>', $userId ] ]
)
->field( [ 'a.to_uid', 'b.name', 'b.avatar', 'b.job_id', 'b.phone', 'b.email', 'c.name as job_name' ,'b.name']
)
->order( [ 'a.id' => 'desc' ] )
->paginate( [ 'list_rows' => 10, 'page' => $page ]
)
->toArray();
// 自己如果是员工则把自己返回在第一页第一个
// if ( $userInfo[ 'is_staff' ] == 1 && $page == 1 )
// {
// $card = self::alias( 'a' )
// ->where( [ [ 'a.uniacid', '=', $uniacid ], [ 'a.uid', '=', $userId ], [ 'a.status', '=', 1 ],
// [ 'b.is_staff', '=', 1 ], [ 'a.to_uid', '=', $userId ] ]
// )
// ->field( [ 'a.to_uid', 'b.name', 'b.avatar', 'b.job_id', 'b.phone', 'b.email', 'c.name as job_name' ]
// )
// ->join( 'longbing_card_user_info b', 'a.to_uid = b.fans_id' )
// ->join( 'longbing_card_job c', 'b.job_id = c.id', 'LEFT' )
// ->find();
// if ($card)
// {
// $card = $card->toArray();
//
// $data[ 'data' ] = array_merge([$card], $data[ 'data' ]);
// }
// }
foreach ($data[ 'data' ] as $index => $item)
{
if ($item['job_name'] === null)
{
$data[ 'data' ][$index]['job_name'] = '未设置职位';
}
}
$data[ 'data' ] = transImages( $data[ 'data' ], [ 'avatar' ] );
return $data;
}
/**
* @Purpose: 默认推荐员工列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function defaultCardList ($page = 1, $uniacid = 0 ,$staff_id = null)
{
$page = intval( $page );
$page = $page ? $page : 1;
$modelUserInfo = new UserInfo();
//Update by jingshuixian 'a.fans_id', 'a.fans_id as to_uid', 修复无法访问的bug
$where = [ [ 'a.uniacid', '=', $uniacid ], [ 'a.is_default', '=', 1 ], [ 'a.is_staff', '=', 1 ]];
if(!empty($staff_id)) $where[] = ['fans_id' ,'<>' , $staff_id];
$data = $modelUserInfo->alias('a')
->where($where)
->field( [ 'a.fans_id', 'a.fans_id as to_uid', 'a.name', 'a.avatar', 'a.job_id', 'a.phone', 'a.email', 'b.name as job_name' ]
)
->join( 'longbing_card_job b', 'a.job_id = b.id', 'LEFT' )
->order( [ 'a.top' => 'desc' ] )
->paginate( [ 'list_rows' => 10, 'page' => $page ]
)
->toArray();
foreach ($data[ 'data' ] as $index => $item)
{
if ($item['job_name'] === null)
{
$data[ 'data' ][$index]['job_name'] = '未设置职位';
}
}
$data[ 'data' ] = transImages( $data[ 'data' ], [ 'avatar' ] );
return $data;
}
//收藏名片
public function createCollection($data)
{
$data['create_time'] = time();
// var_dump($data);die;
$result = $this->save($data);
return !empty($result);
}
//修改
public function updateCollection($filter ,$data)
{
$data['update_time'] = time();
$result = $this->where($filter)->update($data);
return !empty($result);
}
//获取收藏名片总数
public function getCollectionCount($filter)
{
$result = $this->where($filter)->count();
return $result;
}
//获取收藏名片信息
public function checkCollection($filter)
{
$result = $this->where($filter)->field('id ,status')->find();
if($result) $result = $result->toArray();
return $result;
}
//获去信息
public function getCollection($filter)
{
$result = $this->where($filter)->find();
if($result) $result = $result->toArray();
return $result;
}
//获取需要更新的rate数据总数
// public function getCollectionJoinRateCount()
// {
// $time = time() - 24*60*60;
// $result = $this->alias('a')
// ->leftJoin('longbing_card_rate b' ,'a.uid = b.user_id && a.to_uid = b.staff_id && a.uniacid = b.uniacid')
//// ->whereOr([['b.update_time' ,'<' ,$time] ,['b.id' , '=',null]])
//// ->fetchSql()
// ->count();
//// var_dump($result);die;
// return $result;
// }
//获取需要更新的rate数据
// public function listCollectionJoinRate($page_config = ['page' => 1 ,'page_count' =>200])
// {
// $time = time() - 24*60*60;
// $result = $this->alias('a')
// ->leftJoin('longbing_card_rate b' ,'a.uid = b.user_id && a.to_uid = b.staff_id && a.uniacid = b.uniacid')
// ->whereOr([['b.update_time' ,'<' ,$time] ,['b.id' ,'=' ,null]])
// ->field('a.id ,b.id as rate_id')
// ->page($page_config['page'] ,$page_config['page_count'])
// ->select();
// if(!empty($result)) $result = $result->toArray();
// return $result;
// }
//
public function getCollectionJoinRateCount()
{
$time = time() - 24*60*60;
$result = $this->where([['update_rate_time' ,'<' ,$time]])->count();
// var_dump($result);die;
return $result;
}
//获取需要更新的rate数据
public function listCollectionJoinRate($page_config = ['page' => 1 ,'page_count' =>200])
{
$time = time() - 24*60*60;
$result = $this->where([['update_rate_time' ,'<' ,$time]])
->field('id')
->page($page_config['page'] ,$page_config['page_count'])
->select();
if(!empty($result)) $result = $result->toArray();
return $result;
}
public function getYesterdaylist($where){
$data = $this->alias('a')
->join( 'longbing_card_user_info b', 'a.to_uid = b.fans_id')
->join( 'longbing_card_user d', 'b.fans_id = d.id && d.is_staff = 1','left')
->join( 'longbing_card_job c', 'c.id = b.job_id ','left')
->field('a.to_uid,count(a.to_uid) as number,a.uniacid,b.name,avatar,c.name as job_name,nickName,avatarUrl')
->where($where)
->limit(3)
->group('a.to_uid')
->order('number desc ,a.to_uid asc')
->whereDay('a.create_time','yesterday')
->select()->toArray();
foreach ($data as $k=>$v){
if(!$v['name']){
$data[$k]['name'] = $v['nickName'];
}
if(!$v['avatar']){
$data[$k]['avatar'] = $v['avatarUrl'];
}
if(!$v['job_name']){
$data[$k]['job_name'] = '未设置职位';
}
}
$data = transImagesOne($data,['avatar']);
return $data;
}
public function getlistAll($where,$page,$list_rows,$type =0,$desc = 0){
if($desc == 0){
$de = 'asc';
}else{
$de = 'desc';
}
if($desc == 0){
$de1 = 'desc';
}else{
$de1 = 'asc';
}
$data = $this->alias('a')
->join( 'longbing_card_user_info b', 'a.to_uid = b.fans_id')
->join( 'longbing_card_user d', 'b.fans_id = d.id && d.is_staff = 1','left')
->join( 'longbing_card_job c', 'c.id = b.job_id ','left')
->field('a.to_uid,count(a.to_uid) as number,a.uniacid,b.name,avatar,c.name as job_name,nickName,avatarUrl')
->where($where)
->group('a.to_uid')
->order("number $de,a.to_uid $de1")
->paginate([ 'list_rows' => $list_rows, 'page' => $page ])->each(function ($item,$key)use ($type){
if(!$item['name']){
$item['name'] = $item['nickName'];
}
if(!$item['avatar']){
$item['avatar'] = $item['avatarUrl'];
}
if(!$item['job_name']){
$item['job_name'] = '未设置职位';
}
return $item;
})->toArray();
$data = transImagesOne($data,['avatar']);
return $data;
}
//查询昨天新增客户的数据
public function getTodaylist($where){
$data = $this->alias('a')
//->leftJoin( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->join( 'longbing_card_user c', 'a.uid = c.id' )
->where($where)
->field('a.to_uid as user_id,count(a.to_uid) as number,a.uniacid')
->whereDay('a.create_time','yesterday')
->group( 'a.to_uid' )
->select()->toArray();
if($data){
foreach ($data as $key=>$val){
$data[$key]['table'] = 'customer';
$data[$key]['create_time'] = strtotime("-1 day");
}
$stat = new CardStatistics();
$stat->createRows($data);
}
return $data;
}
public function getCount($where){
return $this->alias('a')
->where($where)
->count();
}
//查询今天线索
public function today($where){
return $this->alias('a')
->leftJoin( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->join( 'longbing_card_user c', 'a.uid = c.id' )
->where($where)
->whereDay('a.create_time')
->group( 'a.uid, a.to_uid' )
->count();
}
//查询七天类的客户数量
public function weekToday($where){
$weekday = date("Y-m-d",strtotime("-6 day"));
$data = $this->alias('a')
->leftJoin( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->join( 'longbing_card_user c', 'a.uid = c.id' )
->where($where)
->whereWeek('a.update_time',$weekday)
->group( 'a.uid, a.to_uid' )
->count();
return $data;
}
//查询昨天线索的数据
public function Yesterday($where){
return $this->alias('a')
->leftJoin( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->join( 'longbing_card_user c', 'a.uid = c.id' )
->where($where)
->whereDay('a.create_time','yesterday')
->group( 'a.uid, a.to_uid' )
->count();
}
// public function getLookCount($where){
// return $this->alias('a')
// ->join( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
// ->where($where)
// ->count();
// }
//查询客户当天的数据
public function todayLook($where){
return $this->alias('a')
->join( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->whereDay('a.update_time')
->where($where)
->count();
}
//更新变更线索人数
// public function changeNember($where){
// $data = $this->where($where)
// ->alias('a')
// //->join( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
// ->field('a.to_uid as user_id,count(a.to_uid) as number,a.uniacid')
// //->whereDay('a.create_time')
// ->group('a.to_uid')
// ->select()
// ->toArray();
// if($data){
// $stat = new CardStatistics();
// foreach ($data as $key=>$val){
// $id = $stat->getUserid(['user_id'=>$val['user_id'],'sign'=>'customer_no']);
// if($id){
// $stat->updateinfo(['user_id'=>$val['user_id'],'sign'=>'customer_no'],['number'=>$val['number'],'create_time'=>strtotime("-1 day")]);
// }else{
// $val['sign'] = 'customer_no';
// $val['create_time'] = strtotime("-1 day");
// $stat->addinfo($val);
// }
// }
// }
// return $data;
// }
//查询线索数据
public function todayUid($where){
$data = $this->alias('a')
->leftJoin( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->join( 'longbing_card_user c', 'a.uid = c.id','left' )
->where($where)
->group( 'a.uid, a.to_uid' )
->count();
return $data;
}
//线索池
public function xian($where){
$sc1 = $this->alias('a')
//->join( 'longbing_card_collection b', 'a.uid = b.user_id' )
->field('uid,to_uid,intention')
->where($where)
->column('to_uid','uid');
// if($sc1){
// foreach ($sc1 as $key=>$value){
// $uid = $this->where(['uid'=>$key,'intention'=>1])->value('uid');
// if($uid){
// unset($sc1[$key]);
// }
// }
// }
return count($sc1);
}
//今天线索池
public function Todayxian($where){
$sc1 = $this->alias('a')
//->join( 'longbing_card_collection b', 'a.uid = b.user_id' )
->field('uid,to_uid,intention')
->whereDay('create_time')
->where($where)
->column('to_uid','uid');
// if($sc1){
// foreach ($sc1 as $key=>$value){
// $uid = $this->where(['uid'=>$key,'intention'=>1])->value('uid');
// if($uid){
// unset($sc1[$key]);
// }
// }
// }
return count($sc1);
}
//总线索数量
public function allXian($where){
$data = $this->alias('a')->leftJoin( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->join( 'longbing_card_user c', 'a.uid = c.id' )
->where($where)
->group( 'a.uid, a.to_uid' )->count();
return $data;
}
public function getlistCount($where){
return $this->where($where)->count();
}
//累计访问量
public function visit($where){
$visit_number = 0;
$visit = $this->alias('a')
->join( 'longbing_card_count b', 'a.uid = b.user_id && a.to_uid = b.to_uid' )
->field('count(a.to_uid) as number')
->where($where)
->group('a.to_uid')
// ->where($where)
->select()->toArray();
if($visit){
foreach ($visit as $value){
$visit_number += $value['number'];
}
}
return $visit_number;
}
public function staffInfo($where_s,$page,$list_rows){
$data = $this->alias('a')
->join( 'longbing_card_user_info b', 'a.to_uid = b.fans_id' )
->join( 'longbing_card_company c', 'b.company_id = c.id')
->join( 'longbing_card_job d', 'b.job_id = d.id','left' )
->join( 'longbing_card_user e', 'e.id = b.fans_id' )
->where($where_s)
->field('avatar,b.name,company_id,job_id,b.phone,a.create_time,c.name as company_name,d.name as job_name,b.fans_id,a.uniacid,b.create_time as start_time,a.to_uid,e.create_time as start_time')
->find();//
$arr =[] ;
$follow_info = [];
$radar_count = [];
$behavior = [];
$ability = [];
$Interest = [];
$active = [];
$start_time = 0;
if($data){
$data = $data ->toArray();
if ($data['job_name'] === null)
{
$data[ 'job_name' ] = '未设置职位';
}
$timediff = time() - $data['start_time'];
$data['day'] = intval($timediff / 86400);
$data['time'] = '今天'.date('H:i',time());
// $card_value = new CardValue();
// $rest = $card_value->bossGetAiValue($data['to_uid'],$data['uniacid']);
// $data['total_info'] = $rest['data'];
$data['create_time'] = date('Y-m-d',$data['create_time']);
//新增线索
$collect = new Collection();
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
$beginbeforeYesterday=mktime(0,0,0,date('m'),date('d')-2,date('Y'));
$endbeforeYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'))-1;
$user_id = $data['fans_id'];
$stat = new CardStatistics();
//累计线索
// $wherex[] =[
// ['user_id','=',$user_id],
// ['uniacid','=',$this->_uniacid],
// ['table','=','customer']
// ];
//查询关联公司的员工
// $user_info = new UserInfo();
//一个公司的员工
// $other_staff = $user_info->getIsStaff($user_id,$data['uniacid']);
//日增长线索
$whes[] = [
['intention','=',0],
['a.uid','<>',$user_id],['a.to_uid','=',$user_id],['a.uniacid','=',$data['uniacid']]
];
$cumulative_clues = $collect->todayUid($whes);
$todayKh = $collect->today($whes);
//昨天线索
$yesterdaytodayKh = $collect->Yesterday($whes);
//前天的线索
$whes[1] =[
[ 'a.create_time', 'BETWEEN', [ $beginbeforeYesterday, $endbeforeYesterday ]]
];
$beforXs = $collect->todayUid($whes);
//昨天对比前天新增数
$contrastKh =$yesterdaytodayKh-$beforXs;
//线索池
$whes1[] =[
['a.uid','<>',$user_id],['a.to_uid','=',$user_id],['a.uniacid','=',$data['uniacid']]
];
$xs = $collect->todayUid($whes1);
//今天的线索池
$whes1[1] =[[ 'a.create_time', 'BETWEEN', [ $beginToday, $endToday ]]];
$todayxs = $collect->todayUid($whes1);
//昨天线索池
$whes1[1] =[[ 'a.create_time', 'BETWEEN', [ $beginYesterday, $endYesterday ]]];
$yesterdayxs = $collect->todayUid($whes1);
//前天线索池
$whes1[1] =[[ 'a.create_time', 'BETWEEN', [ $beginbeforeYesterday, $endbeforeYesterday ]]];
$beforexs = $collect->todayUid($whes1);
//昨天对比前天新增数
$contrastxs =$yesterdayxs-$beforexs;
$whez[] =[
['a.uid','<>',$user_id],
['intention','=',1],
['a.to_uid','=',$user_id],
['a.uniacid','=',$data['uniacid']]
];
// //累计客户数量
$customer = $collect->todayUid($whez);
//日增长客户
$today = $collect->today($whez);
//日线索增长
$addTodayxs = $todayxs-$today;
//昨天客户数
$yesterdaykh = $collect->Yesterday($whez);
//前天的客户
$whez[] = [
[ 'a.update_time', 'BETWEEN', [ $beginbeforeYesterday, $endbeforeYesterday ]]
];
$beforkh = $collect->todayUid($whez);
//昨天对比前天新增数
$contrastkh =$yesterdaykh-$beforkh;
//累计访问量
$card_count = new CardCount();
// $visit_number = $stat->getCustomerCount([['user_id','=',$user_id],
// ['sign','=','praise'],
// ['type','=',2],['uniacid','=',$this->_uniacid]]);
//今天的访问量
$wheres[] = [
['to_uid','=',$user_id],
['sign','=','praise'],
['type','=',2],
['uniacid','=',$data['uniacid']]
];
$visit_number = $card_count->getCount($wheres);
$wheres[1] =[[ 'create_time', 'BETWEEN', [ $beginToday, $endToday ]]];
$todayVisitNumber = $card_count->getCount($wheres);
//昨天的访问量
$wheres[1] = [
[ 'create_time', 'BETWEEN', [ $beginYesterday, $endYesterday ] ],
];
$yesterdayVisit = $card_count->getCount($wheres);
//前天的访问量
$wheres[1] = [
[ 'create_time', 'BETWEEN', [ $beginbeforeYesterday, $endbeforeYesterday] ],
];
$beforVisit = $card_count->getCount($wheres);
//昨天对比前天新增数
$contrastVisit =$yesterdayVisit-$beforVisit;
//咨询
//消息
$whereMsg[] = [
['message_type','=','text'],
['deleted','=',0],
['uniacid','=',$this->_uniacid],
['target_id','=',$user_id]
];
$card_message = new CardMessage();
//累计消息
$message = $card_message->getCount($whereMsg);
//今天消息
$whereMsg[1] = [
[ 'create_time', 'BETWEEN', [ $beginToday, $endToday ] ],
];
$today_message = $card_message->getCount($whereMsg);
//昨天的消息
$whereMsg[1] = [
[ 'create_time', 'BETWEEN', [ $beginYesterday, $endYesterday ] ],
];
$Yesterday_message = $card_message->getCount($whereMsg);
//前天的消息
$whereMsg[1] = [
[ 'create_time', 'BETWEEN', [ $beginbeforeYesterday, $endbeforeYesterday ] ],
];
$before_message = $card_message->getCount($whereMsg);
$zx = $card_count->zxInfo($user_id,[],1);
$zx = $zx+$message;
$where1 = ['create_time','BETWEEN',[ $beginToday, $endToday ]];
$zxtoday = $card_count->zxInfo($user_id,$where1,1);
$zxtoday = $zxtoday+$today_message;
//昨天的咨询
$where1 = ['create_time','BETWEEN',[ $beginYesterday, $endYesterday ]];
$zxYesterday = $card_count->zxInfo($user_id,$where1,1);
$zxYesterday = $zxYesterday+$Yesterday_message;
//前天的咨询
$where1 = ['create_time','BETWEEN',[ $beginbeforeYesterday, $endbeforeYesterday ]];
$zxbefore = $card_count->zxInfo($user_id,$where1,1);
$zxbefore = $zxbefore+$before_message;
//昨天对比前天新增数
$contrastzx =$zxYesterday-$zxbefore;
//跟进客户次数
$user_mark = new UserFollow();
$where3[] = [
['staff_id','=',$user_id],
['status','=',1],
//['uniacid','=',$this->_uniacid]
];
$mark = $user_mark->getCount($where3);
$where3[1] = [
[ 'create_time', 'BETWEEN', [ $beginToday, $endToday ] ],
];
$today_mark = $user_mark->getCount($where3);
//昨天的跟进客户
$where3[1] = [
[ 'create_time', 'BETWEEN', [ $beginYesterday, $endYesterday ] ],
];
$Yesterday_mark = $user_mark->getCount($where3);
//前天的跟进客户
$where3[1] = [
[ 'create_time', 'BETWEEN', [ $beginbeforeYesterday, $endbeforeYesterday ] ],
];
$before_mark = $user_mark->getCount($where3);
$contrastzmark =$Yesterday_mark-$before_mark;
//被转发次数
// $forward = new CardForward();
$where4[] = [
['to_uid','=',$user_id],
['type','=',4],
['sign','=','praise'],
['uniacid','=',$data['uniacid']]
];
$forward_count = $card_count->getCount($where4);
$today_forward_count =$card_count->gettoday($where4);
//昨天转发
$Yesterday_forward_count =$card_count->getYesterday($where4);
//前天转发
$where4[] = [
[ 'create_time', 'BETWEEN', [$beginbeforeYesterday, $endbeforeYesterday] ],
];
$before_forward_count =$card_count->getCount($where4);
$contrastzforward =$Yesterday_forward_count-$before_forward_count;
//累计被点赞次数
$where5[] = [
['to_uid','=',$user_id],
['type','=',3],
['sign','=','praise'],
['uniacid','=',$data['uniacid']]
];
$dz = $card_count->getCount($where5);
$where5[1] = [
[ 'create_time', 'BETWEEN', [ $beginToday, $endToday ] ],
];
$today_dz = $card_count->getCount($where5);
//昨天点赞
$where5[1] = [
[ 'create_time', 'BETWEEN', [$beginYesterday, $endYesterday] ],
];
$Yesterday_dz = $card_count->getCount($where5);
//前天点赞
$where5[1] = [
[ 'create_time', 'BETWEEN', [$beginbeforeYesterday, $endbeforeYesterday] ],
];
$before_dz = $card_count->getCount($where5);
$contrastzdz =$Yesterday_dz-$before_dz;
//累计被保存次数
$where6[] = [
['to_uid','=',$user_id],
['type','=',1],
['sign','=','copy'],
['uniacid','=',$data['uniacid']]
];
$bc = $card_count->getCount($where6);
$where6[1] = [
[ 'create_time', 'BETWEEN', [ $beginToday, $endToday ] ],
];
$today_bc = $card_count->getCount($where6);
//昨天保存
$where6[1] = [
[ 'create_time', 'BETWEEN', [$beginYesterday, $endYesterday] ],
];
$Yesterday_bc = $card_count->getCount($where6);
//前天保存
$where6[1] = [
[ 'create_time', 'BETWEEN', [$beginbeforeYesterday, $endbeforeYesterday] ],
];
$before_bc = $card_count->getCount($where6);
$contrastzbc =$Yesterday_bc-$before_bc;
//商城订单笔数和销售金额
$admin_goods = new CardShopOrder();
$where7[]= [
['company_id','=',$data['company_id']],
['to_uid','=',$user_id],
['uniacid','=',$data['uniacid']]
];
$sales_count = $admin_goods->getGoosSale($where7);
//昨天的商品销售
$where7[] = [
[ 'create_time', 'BETWEEN', [$beginYesterday, $endYesterday] ],
];
$Yesterday_sales_count = $admin_goods->getGoosSale($where7);
//数据
$arr = [
'count'=>[
[
[
'name'=>'累计线索(人)',
'number'=>$xs,
'rate'=>$todayKh,
],
[
'name'=>'线索池(人)',
'number'=>$cumulative_clues,
// 'text'=>$title,
'rate'=>$addTodayxs,
// 'up'=>$up
],
[
'name'=>'累计客户(人)',
'number'=>$customer,
'rate'=>$today,
],
[
'name'=>'累计访问量(次)',
'number'=>$visit_number,
'rate'=>$todayVisitNumber,
],
[
'name'=>'累计咨询(次)',
'number'=>$zx,
'rate'=>$zxtoday,
],
[
'name'=>'累计跟进客户(次)',
'number'=>$mark,
'rate'=>$today_mark,
],
[
'name'=>'累计被转发(次)',
'number'=>$forward_count,
'rate'=>$today_forward_count,
],
[
'name'=>'累计被点赞(次)',
'number'=>$dz,
'rate'=>$today_dz,
],
[
'name'=>'累计被保存(次)',
'number'=>$bc,
'rate'=>$today_bc,
]
],
[
[
'name'=>'新增线索(人)',
'number'=>$yesterdaytodayKh,
'rate'=>$contrastKh,
],
[
'name'=>'变动线索池(人)',
'number'=>$yesterdayxs,
'rate'=>$contrastxs,
],
[
'name'=>'新增客户(人)',
'number'=>$yesterdaykh,
'rate'=>$contrastkh,
],
[
'name'=>'新增访问量(次)',
'number'=>$yesterdayVisit,
'rate'=>$contrastVisit,
],
[
'name'=>'新增咨询(次)',
'number'=>$zxYesterday,
'rate'=>$contrastzx,
],
[
'name'=>'新增跟进客户(次)',
'number'=>$Yesterday_mark,
'rate'=>$contrastzmark,
],
[
'name'=>'新增被转发(次)',
'number'=>$Yesterday_forward_count,
'rate'=>$contrastzforward,
],
[
'name'=>'新增被点赞(次)',
'number'=>$Yesterday_dz,
'rate'=>$contrastzdz,
],
[
'name'=>'新增被保存(次)',
'number'=>$Yesterday_bc,
'rate'=>$contrastzbc,
]
],
],
'goods_sale'=>[
$sales_count,$Yesterday_sales_count
]
];
$title1 = '日增涨';
$title2 = '日减少';
$title3 = '持平 -';
foreach ($arr['count'][0] as $key=>$value){
if($value['rate']>0){
$arr['count'][0][$key]['text'] = $title1;
$arr['count'][0][$key]['up'] =1;
}elseif ($value['rate']==0){
$arr['count'][0][$key]['up'] =-1;
$arr['count'][0][$key]['text'] = $title3;
}else{
$arr['count'][0][$key]['up'] =0;
$arr['count'][0][$key]['text'] = $title2;
}
$arr['count'][0][$key]['rate'] = abs($value['rate']);
}
foreach ($arr['count'][1] as $k=>$val){
if($val['rate']>0){
$arr['count'][1][$k]['text'] = $title1;
$arr['count'][1][$k]['up'] =1;
}elseif ($val['rate']==0){
$arr['count'][1][$k]['up'] =-1;
$arr['count'][1][$k]['text'] = $title3;
}else{
$arr['count'][1][$k]['up'] =0;
$arr['count'][1][$k]['text'] = $title2;
}
$arr['count'][1][$k]['rate'] = abs($val['rate']);
}
//跟进客户记录
$follow_info = UserFollow::alias( 'a' )
->join( 'longbing_card_user b', 'a.user_id = b.id')
->field( [ 'content', 'a.create_time','user_id','b.nickName as name' ] )
->where( [
[ 'a.staff_id', '=',$user_id ] ]
)->order( 'a.id', 'desc' )
->paginate( [ 'list_rows' => 4, 'page' => 1 ])->toArray();
$follow_info['data'] = lbHandelRadarDate( $follow_info['data'], 'create_time' );
foreach ($follow_info['data'] as $index => $item )
{
$follow_info['data'][ $index ][ 'create_time' ] = date( 'Y-m-d H:i', $item[ 'create_time' ] );
}
$ardar = new CardCount();
$radar_count = $ardar->radarList([ [ 'a.to_uid', '=', $user_id ],[ 'a.user_id', '<>', $user_id ] ], 1,4);
$radar_count['data'] = lbHandelRadarDate( $radar_count['data'], 'create_time' );
if($radar_count['data']){
foreach ($radar_count['data'] as $k => $v )
{
$radar_count['data'][ $k ][ 'create_time' ] = date( 'Y-m-d H:i', $v[ 'create_time' ] );
}
}
//客户行为
$card_count = new CardCount();
$behavior = $card_count->getsss($user_id,$data['uniacid'],1);
//能力雷达
$card_value = new CardValue();
$ability = $card_value->bossGetAiValue($user_id,$data['uniacid']);
//兴趣占比
$Interest = $ardar->doPageBossInterest(['to_uid','=',$user_id],$data['uniacid']);
//客户活跃度
$active = $ardar->active($user_id,$data['uniacid']);
$timediff = time() - $data['start_time'];
$start_time = intval($timediff / 86400);
}
$data['look'] =$arr;
$data['interaction'] =$radar_count;
$data['follow_info'] =$follow_info;
$data['behavior'] =$behavior;
$data['ability'] =$ability;
$data['interest'] =$Interest;
$data['active'] =$active;
$data['day'] = $start_time;
$data = transImagesOne($data, ['avatar']);
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-03-30 15:06
* @功能说明:获取浏览过的名片
*/
public function getCard($uid,$uniacid){
//查看浏览过的名片
$data = $this->alias('a')
->join('longbing_card_user b', 'a.to_uid = b.id AND b.is_staff = 1')
->where(['uid'=>$uid])
->value('to_uid');
//如果没有就给一个推荐的
if(empty($data)){
$data = Db::name('longbing_card_user_info')->where(['uniacid'=>$uniacid,'is_default'=>1])->value('fans_id');
}
//修改
if(!empty($data)){
//修改最近浏览的名片
Db::name('longbing_card_user')->where(['id'=>$uid])->update(['last_staff_id'=>$data]);
//增肌默认分配次数
Db::name('longbing_card_user')->where(['id'=>$data])->inc('auto_count');
//缓存的键
$key = 'longbing_card_user_' . $uid;
//删除缓存
delCache($key,$uniacid);
}
return $data;
}
}

358
app/card/model/Company.php Normal file
View File

@@ -0,0 +1,358 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class Company extends BaseModel
{
//定义表名
protected $name = 'longbing_card_company';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 创建公司
* @Author: yangqi
* @create time : 2019年11月25日20:28:45
*/
public function createRow($data)
{
$data['create_time'] = time();
$result = $this->save($data);
return !empty($result);
}
/**
* @Purpose: 获取公司信息
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getInfo ( $uniacid = 0, $userId = 0, $company_id = 0 )
{
$company = [];
if ( $userId )
{
$userInfo = UserInfo::where( [ [ 'fans_id', '=', $userId ] ] )
->find();
if ( $userInfo && $userInfo[ 'company_id' ] )
{
$company = self::where( [ [ 'id', '=', $userInfo[ 'company_id' ] ], [ 'status', '=', 1 ] ] )
// ->withoutField( [ 'auth_code' ] )
->find();
}
}
if ( $company_id )
{
$company = self::where( [ [ 'id', '=', $company_id ], [ 'status', '=', 1 ] ] )
// ->withoutField( [ 'auth_code' ] )
->find();
}
if ( is_array( $company ) && $company = [] )
{
$company = self::where( [ [ 'status', '=', 1 ], [ 'uniacid', '=', $uniacid ] ] )
// ->withoutField( [ 'auth_code' ] )
->find();
}
if ( $company )
{
$company = $company->toArray();
$company = transImages( $company, [ 'culture' ] );
$company = transImagesOne( $company, [ 'logo', 'desc' ] );
$company[ 'shop_bg' ] = $company[ 'desc' ];
$company[ 'carousel' ] = $company[ 'culture' ];
}
return $company;
}
/**
* @author chenniang
* @DataTime: 2020-08-21 14:02
* @功能说明:替换顶级公司的名字
*/
public function changeTopName($company){
if(!empty($company['top_id'])){
$dis = [
'status' => 1,
'id' => $company['top_id'],
'uniacid'=> $company['uniacid']
];
$top_name = $this->where($dis)->value('name');
$short_name = $this->where($dis)->value('short_name');
if(!empty($top_name)){
$company['name'] = $top_name;
$company['short_name'] = $short_name;
}
}
return $company;
}
/**
* @Purpose: 根据用户id返回公司列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getListByUser ( $user_id, $uniacid, $is_all = 0, $company_id = 0 )
{
if ( $is_all )
{
$companyList = self::where( [ [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1, ], [ 'pid', '=', 0 ] ] )
->field( [ 'id', 'pid', 'name', 'logo', 'addr' ] )
->order('top desc,pid asc,id desc')
->select()
->toArray();
$sonList = self::where( [ [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1, ], [ 'pid', '<>', 0 ] ] )
->field( [ 'id', 'pid', 'name', 'logo', 'addr' ] )
->order('top desc,pid asc,id desc')
->select()
->toArray();
$companyList = self::handleCompanyLevel( $companyList, $sonList );
}
else
{
$modelCardBoss = new CardBoss();
$check = $modelCardBoss->where( [ [ 'user_id', '=', $user_id ], [ 'uniacid', '=', $uniacid ],
[ 'boss', '<>', '' ] ]
)
->field( [ 'boss' ] )
->find();
if ( !$check )
{
return $this->getListByUser( $user_id, $uniacid, $is_all = 1 );
}
$tmpArr = explode( ',', $check[ 'boss' ] );
$companyList = self::where( [ [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1, ], [ 'id', 'in', $tmpArr ] ] )
->field( [ 'id', 'pid', 'name', 'logo', 'addr' ] )
->order('top desc,pid asc,id desc')
->select()
->toArray();
foreach ( $companyList as $index => $item )
{
$companyList[ $index ][ 'sec' ] = [];
}
}
$companyList = transImagesOne( $companyList, [ 'logo' ] );
foreach ( $companyList as $index => $item )
{
$companyList[ $index ][ 'selected' ] = 0;
if ( isset( $item[ 'id' ] ) && $item[ 'id' ] == $company_id )
{
$companyList[ $index ][ 'selected' ] = 1;
}
}
return $companyList;
}
/**
* @Purpose: 处理公司层级--无限级
*
* @Param: array $list 顶级公司列表
* @Param: array $son 部门列表
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function handleCompanyLevel ( $list, $son, $item_name = 'sec' )
{
foreach ( $list as $index => $item )
{
if ( !isset( $list[ $index ][ $item_name ] ) )
{
$list[ $index ][ $item_name ] = array();
}
foreach ( $son as $key => $value )
{
if ( $item[ 'id' ] == $value[ 'pid' ] )
{
array_push( $list[ $index ][ $item_name ], $value );
unset( $son[ $key ] );
}
}
if ( $list[ $index ][ $item_name ] && count( $list[ $index ][ $item_name ] ) && count( $son ) )
{
$list[ $index ][ $item_name ] = self::handleCompanyLevel( $list[ $index ][ $item_name ], $son, $item_name );
}
}
return $list;
}
/**
* @Purpose: 改变公司状态
*
* @Param$company_id number 公司id
* @Param$method number 操作类型 0 = 下架 1 = 上架 2 = 删除
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function updateStatus ( $company_id, $method = 0 )
{
$result = false;
switch ( $method )
{
case 0:
$result = self::update( [ 'status' => 0 ], [ 'id' => $company_id ] );
$this->updateSonCompanyInfo( $company_id, [ 'status' => 0 ] );
break;
case 1:
$result = self::update( [ 'status' => 1 ], [ 'id' => $company_id ] );
break;
case 2:
$result = self::update( [ 'status' => -1 ], [ 'id' => $company_id ] );
$this->updateSonCompanyInfo( $company_id, [ 'status' => -1 ] );
break;
default:
return false;
}
if ( $result === false )
{
return false;
}
return $result;
}
/**
* @Purpose: 改变下级公司信息
*
* @Param$company_id number 公司id
* @Param$data array 修改内容
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function updateSonCompanyInfo ( $company_id, $data )
{
$list = self::where( [ [ 'pid', '=', $company_id ] ] )
->select()
->toArray();
foreach ( $list as $index => $item )
{
$check = self::where( [ [ 'pid', '=', $item[ 'id' ] ] ] )
->count();
if ( $check )
{
$this->updateSonCompanyInfo( $item[ 'id' ], $data );
}
self::update( $data, [ 'id' => $item[ 'id' ] ] );
}
return true;
}
/**
* @Purpose: 获取公司和部门名
*
* @Param$company_id number 公司id
*
* @Author: zzf
*
* @Return: mixed 查询返回值(结果集对象)
*/
public function getCompanyAndDepartmentName ( $company_id )
{
$info = self::where( [ [ 'id', '=', $company_id ] ] )
->find();
if ( !$info )
{
return [ '未设置公司', '未设置部门' ];
}
if ( $info[ 'pid' ] == 0 )
{
return [ $info[ 'name' ], '未设置部门' ];
}
$topCompany = $this->getTopCompany( $info[ 'pid' ] );
$companyName = '未设置公司';
if ( $topCompany && $topCompany[ 'status' ] )
{
$companyName = $topCompany[ 'name' ];
}
return [ $companyName, $info[ 'name' ] ];
}
protected function getTopCompany ( $pid )
{
$info = self::where( [ [ 'id', '=', $pid ] ] )
->find();
if ( !$info )
{
return '';
}
if ( $info[ 'pid' ] )
{
return $this->getTopCompany( $info[ 'pid' ] );
}
return $info;
}
public function getCompany($filter ,$field = [])
{
if(isset($filter['company_id']))
{
$filter['id'] = $filter['company_id'];
unset($filter['company_id']);
}
$result = $this->where($filter);
if(!empty($field)) $result = $result->field($field);
$result = $result->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
}

71
app/card/model/Config.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class Config extends BaseModel
{
//定义表名
protected $name = 'longbing_card_config';
protected static function init ()
{
//TODO:初始化内容
}
public function initConfig ($uniacid)
{
return self::create( [ 'uniacid' => $uniacid,'agreement'=>'' ] );
}
public function getConfig ($uniacid)
{
$key = 'longbing_card_config_';
$cacheData = getCache($key, $uniacid);
// 暂时关闭缓存
$cacheData = false;
if ($cacheData)
{
$cacheData['fromCache'] = 1;
return $cacheData;
}
$data = self::where( [ [ 'uniacid', '=', $uniacid ] ] )
->find();
if ( !$data )
{
$data = $this->initConfig($uniacid);
}
$data = $data->toArray();
$data = transImagesOne( $data, [ 'vr_cover', 'default_video', 'default_voice', 'appoint_pic', 'click_copy_show_img',
'shop_carousel_more', 'copyright', 'default_video_cover' ], $uniacid
);
setCache( $key, $data, 36000, $uniacid );
return $data;
}
//获取
public function getConfigByUniacid($uniacid)
{
$result = $this->where(['uniacid' => $uniacid])->find();
if(!empty($result)){
$result = $result->toArray();
$result = transImagesOne($data, [ 'vr_cover', 'default_video', 'default_voice', 'appoint_pic', 'click_copy_show_img',
'shop_carousel_more', 'copyright', 'default_video_cover' ], $uniacid);
}
return $result;
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\Model;
class DefaultSetting extends BaseModel
{
//定义表名
protected $name = 'longbing_card_default_setting';
/**
* @author chenniang
* @DataTime: 2020-03-18 12:23
* @功能说明:查找配置
*/
public function settingInfo($dis,$field='*'){
$data = $this->where($dis)->find();
if(empty($data)){
$dis['my_photo_cover'] = !empty($dis['my_photo_cover'])?$dis['my_photo_cover']:'';
$dis['share_text'] = !empty($dis['share_text'])?$dis['share_text']:'';
$this->insert($dis);
}
return $this->where($dis)->field($field)->find()->toArray();
}
/**
* @author chenniang
* @DataTime: 2020-03-18 12:24
* @功能说明:配置编辑
*/
public function settingUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
}

33
app/card/model/Job.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace app\card\model;
use app\BaseModel;
class Job extends BaseModel
{
//定义表名
protected $name = 'longbing_card_job';
protected static function init ()
{
//TODO:初始化内容
}
/**
* @Purpose: 创建职位
*
* @Author: yangqi
*
* @Return: boolean
*/
public function createRow($data)
{
$data['create_time'] = time();
$result = $this->save($data);
return !empty($result);
}
}

453
app/card/model/User.php Normal file
View File

@@ -0,0 +1,453 @@
<?php
namespace app\card\model;
use app\BaseModel;
use longbingcore\wxcore\Excel;
use think\Model;
class User extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user';
protected static function init ()
{
//TODO:初始化内容
}
public function searchNickNameAttr($query, $value, $data)
{
$query->where('nickName','like', '%' . $value . '%');
}
public function createUser($data)
{
$data['create_time'] = time();
$result = $this->save($data);
return !empty($result);
}
public function updateUser($filter ,$data)
{
$data['update_time'] = time();
$result = $this->where($filter)->update($data);
return !empty($result);
}
public function getUser($filter)
{
$result = $this->where($filter)->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
public function listUser($filter)
{
}
/**
* @param $where
* @功能说明:名片导出
* @author chenniang
* @DataTime: 2020-04-14 14:41
*/
public function cardExcel($where,$mapor,$type=0,$start_time='',$end_time=''){
$data = User::alias( 'a' )
->join( 'longbing_card_user_info b', 'b.fans_id = a.id' ,'LEFT')
->join( 'longbing_card_company c', 'b.company_id = c.id', 'LEFT' )
->join( 'longbing_card_company d', 'c.top_id = d.id', 'LEFT' )
->where( $where )
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field( [ 'b.id as card_id', 'b.name', 'b.avatar', 'b.job_id', 'b.company_id', 'b.phone',
'b.create_time', 'a.nickName', 'a.avatarUrl', 'a.is_staff', 'a.is_boss',
'c.name as company_name', 'd.name as top_company_name', 'b.is_default', 'a.id' ,'a.import','a.uniacid']
)
->group('a.id')
->order( [ 'a.is_boss' => 'desc', 'a.is_staff' => 'desc', 'a.update_time' => 'desc', 'a.id' => 'desc' ] )
->select()
->toArray();
if(!empty($data)){
foreach ($data as $k=>$v){
if(empty($v['top_company_name'])){
$data[$k]['top_company_name'] = $v['company_name'];
$data[$k]['company_name'] = '未设置部门';
}
$data[$k]['name'] = !empty($v['name'])?$v['name']:$v['nickName'];
//累计客户数量
$data[$k]['all_customer'] = $this->customerCount($v['id'],$v['uniacid'],0,$end_time);
//新增客户
$data[$k]['new_customer'] = $this->customerCount($v['id'],$v['uniacid'],$start_time,$end_time);
//累计线索
$data[$k]['all_collection'] = $this->collectionCount($v['id'],$v['uniacid'],0,$end_time);
//新增线索
$data[$k]['new_collection'] = $this->collectionCount($v['id'],$v['uniacid'],$start_time,$end_time);
//总浏览量
$data[$k]['all_visit'] = $this->visitCount($v['id'],$v['uniacid'],0,$end_time);
//新增浏览量
$data[$k]['new_visit'] = $this->visitCount($v['id'],$v['uniacid'],$start_time,$end_time);
//累计转发
$data[$k]['all_zf'] = $this->zfCount($v['id'],$v['uniacid'],0,$end_time);
//新增转发
$data[$k]['new_zf'] = $this->zfCount($v['id'],$v['uniacid'],$start_time,$end_time);
//累计被保存
$data[$k]['all_save'] = $this->saveCount($v['id'],$v['uniacid'],0,$end_time);
//新增保存
$data[$k]['new_save'] = $this->saveCount($v['id'],$v['uniacid'],$start_time,$end_time);
//累计点赞
$data[$k]['all_dz'] = $this->dzCount($v['id'],$v['uniacid'],0,$end_time);
//新增点赞
$data[$k]['new_dz'] = $this->dzCount($v['id'],$v['uniacid'],$start_time,$end_time);
}
}
$header=[
'序号',
'分公司',
'部门',
'员工姓名',
'客户数',
'',
'累计线索',
'',
'累计浏览量',
'',
'累计被转发',
'',
'累计被保存',
'',
'累计被点赞',
'',
];
if($type==1){
$header_one=[
'',
'',
'',
'',
'新增',
'总数',
'新增',
'总数',
'新增',
'总数',
'新增',
'总数',
'新增',
'总数',
'新增',
'总数',
];
}else{
$header_one=[
'',
'',
'',
'',
'累计新增',
'总数',
'累计新增',
'总数',
'累计新增',
'总数',
'累计新增',
'总数',
'累计新增',
'总数',
'累计新增',
'总数',
];
}
$new_data = [];
$new_data[] = $header_one;
$data = array_values($data);
foreach ($data as $k=>$v){
$info = array();
$info[] = $k+1;
$info[] = $v['top_company_name'];
$info[] = $v['company_name'];
$info[] = $v['name'];
$info[] = $v['new_customer'];
$info[] = $v['all_customer'];
$info[] = $v['new_collection'];
$info[] = $v['all_collection'];
$info[] = $v['new_visit'];
$info[] = $v['all_visit'];
$info[] = $v['new_zf'];
$info[] = $v['all_zf'];
$info[] = $v['new_save'];
$info[] = $v['all_save'];
$info[] = $v['new_dz'];
$info[] = $v['all_dz'];
$new_data[] = $info;
}
$excel = new Excel();
$name = '员工列表';
if($type==1){
$name = date('Y-m-d',$start_time).'——'.'员工列表';
}
if($type==0&&!empty($start_time)&&!empty($end_time)){
$name = date('Y-m-d',$start_time).'——'.date('Y-m-d',$end_time).'-'.'员工列表';
}
// dump($name);exit;
$fileName=$excel->excelExport($name,$header,$new_data,1);
return $data;
}
/**
* @param $user_id
* @param $start_time
* @param $end_time
* @功能说明:客户数量
* @author chenniang
* @DataTime: 2020-04-14 16:14
*/
public function customerCount($user_id,$uniacid,$start_time='',$end_time=''){
//线索模型
$collect = new Collection();
$whez[] =[
['a.uid','<>',$user_id],
['intention','=',1],
['a.to_uid','=',$user_id],
['a.uniacid','=',$uniacid]
];
//如果选了时间
if(!empty($start_time)||!empty($end_time)){
$whez[] = ['a.create_time','between',"$start_time,$end_time"];
}
$new_customer = $collect->todayUid($whez);
return $new_customer;
}
/**
* @param $user_id
* @param $start_time
* @param $end_time
* @功能说明:线索数量
* @author chenniang
* @DataTime: 2020-04-14 16:14
*/
public function collectionCount($user_id,$uniacid,$start_time='',$end_time=''){
//线索模型
$collect = new Collection();
$whes[] = [
['a.uid','<>',$user_id],
['a.to_uid','=',$user_id],
['a.uniacid','=',$uniacid],
// ['intention','=',0],
];
//如果选了时间
if(!empty($start_time)||!empty($end_time)){
$whes[] = ['a.create_time','between',"$start_time,$end_time"];
}
$data = $collect->todayUid($whes);
return $data;
}
/**
* @param $user_id
* @param $start_time
* @param $end_time
* @功能说明:线索数量
* @author chenniang
* @DataTime: 2020-04-14 16:14
*/
public function visitCount($user_id,$uniacid,$start_time='',$end_time=''){
//雷达模型
$card_count = new CardCount();
$wheres[] = [
['to_uid','=',$user_id],
['sign','=','praise'],
['type','=',2],
['uniacid','=',$uniacid]
];
//如果选了时间
if(!empty($start_time)||!empty($end_time)){
$wheres[] = ['create_time','between',"$start_time,$end_time"];
}
//新增浏览量
$data = $card_count->getCount($wheres);
return $data;
}
/**
* @param $user_id
* @param $start_time
* @param $end_time
* @功能说明:转发数量
* @author chenniang
* @DataTime: 2020-04-14 16:14
*/
public function zfCount($user_id,$uniacid,$start_time='',$end_time=''){
//雷达模型
$card_count = new CardCount();
$where4[] = [
['to_uid','=',$user_id],
['type','=',4],
['sign','=','praise'],
['uniacid','=',$uniacid]
];
//如果选了时间
if(!empty($start_time)||!empty($end_time)){
$where4[] = ['create_time','between',"$start_time,$end_time"];
}
//新增浏览量
$data = $card_count->getCount($where4);
return $data;
}
/**
* @param $user_id
* @param $start_time
* @param $end_time
* @功能说明:保存数量
* @author chenniang
* @DataTime: 2020-04-14 16:14
*/
public function saveCount($user_id,$uniacid,$start_time='',$end_time=''){
//雷达模型
$card_count = new CardCount();
$where6[] = [
['to_uid','=',$user_id],
['type','=',1],
['sign','=','copy'],
['uniacid','=',$uniacid]
];
//如果选了时间
if(!empty($start_time)||!empty($end_time)){
$where6[] = ['create_time','between',"$start_time,$end_time"];
}
//保存
$data = $card_count->getCount($where6);
return $data;
}
/**
* @param $user_id
* @param $start_time
* @param $end_time
* @功能说明:点赞数量
* @author chenniang
* @DataTime: 2020-04-14 16:14
*/
public function dzCount($user_id,$uniacid,$start_time='',$end_time=''){
//雷达模型
$card_count = new CardCount();
$where5[] = [
['to_uid','=',$user_id],
['type','=',3],
['sign','=','praise'],
['uniacid','=',$uniacid]
];
//如果选了时间
if(!empty($start_time)&&!empty($end_time)){
$where5[] = ['create_time','between',"$start_time,$end_time"];
}
//点赞
$data = $card_count->getCount($where5);
return $data;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace app\card\model;
use app\BaseModel;
class UserFollow extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_follow';
public function getCount($where){
$data = $this->where($where)->count();
return $data;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace app\card\model;
use app\BaseModel;
use think\facade\Db;
class UserInfo extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_info';
public function createUser($data)
{
$data['create_time'] = time();
$result = $this->save($data);
return !empty($result);
}
public function updateUser($filter ,$data)
{
$data['update_time'] = time();
$result = $this->where($filter)->update($data);
return !empty($result);
}
public function cardList ()
{
$data = $this->where(['fans_id' => 1])->find();
return $data;
}
public function getUserPhone($user_id ,$uniacid = null)
{
$filter = ['fans_id' => $user_id];
if(!empty($uniacid)) $filter['uniacid'] = $uniacid;
$result = $this->where($filter)->field('phone,wechat')->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
public function getStaffMaxAutoCount($filter)
{
$filter['is_staff'] = 1;
$filter['is_default'] = 1;
$count = $this->where($filter)->min('auto_count');
return $count;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace app\card\model;
use app\BaseModel;
use app\dynamic\model\CardStatistics;
class UserMark extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_mark';
public function getCount($where3){
return $this->where($where3)->count();
}
public function getCountlist($where){
$data = $this
->field('staff_id as user_id,count(staff_id) as number,uniacid')
->whereDay('create_time','yesterday')
->group('staff_id')
->where($where)->select()->toArray();
if($data){
foreach ($data as $key=>$val){
$data[$key]['table'] = 'mark';
$data[$key]['create_time'] = strtotime("-1 day");
}
$stat = new CardStatistics();
$stat->createRows($data);
}
return $data;
}
//跟进状态
public function getMarkStatus($where){
$mark = $this->where($where)->value('mark');
if($mark ==2){
$mark ='已成交';
}elseif ($mark ==1){
$mark ='跟进中';
}else{
$mark ='还未跟进';
}
return $mark;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\card\model;
use app\BaseModel;
class UserPhone extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_phone';
public function getUserPhone($user_id ,$uniacid = null)
{
$filter = ['user_id' => $user_id];
if(!empty($uniacid)) $filter['uniacid'] = $uniacid;
$result = $this->where($filter)->field('phone')->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
}

19
app/card/model/UserSk.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace app\card\model;
use app\BaseModel;
class UserSk extends BaseModel
{
//定义表名
protected $name = 'longbing_card_user_sk';
public function getSk($filter)
{
$result = $this->where($filter)->find();
if(!empty($result)) $result = $result->toArray();
return $result;
}
}