You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wkcrm/application/bi/model/Business.php

89 lines
3.2 KiB

4 years ago
<?php
// +----------------------------------------------------------------------
// | Description: 商机
// +----------------------------------------------------------------------
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
// +----------------------------------------------------------------------
namespace app\bi\model;
use think\Db;
use app\admin\model\Common;
use think\Request;
class Business extends Common
{
/**
* 为了数据库的整洁同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
*/
protected $name = 'crm_business';
/**
* [getDataCount 商机count]
* @author Michael_xu
* @param
* @return
*/
function getDataCount($whereArr)
{
$where = [];
$dataCount = $this->where($whereArr)->where($where)->count('business_id');
$count = $dataCount ? : 0;
return $count;
}
/**
* [getDataMoney 商机金额]
* @author Michael_xu
* @param
* @return
*/
function getDataMoney($whereArr)
{
$where = [];
$money = $this->where($whereArr)->where($where)->sum('money');
return $money;
}
/**
* 获取商机list
*
* @param $param
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
function getDataList($param)
{
$page = !empty($param['page']) ? $param['page'] : 1;
$limit = !empty($param['limit']) ? $param['limit'] : 15;
unset($param['page']);
unset($param['limit']);
$userModel = new \app\admin\model\User();
$adminModel = new \app\admin\model\Admin();
$perUserIds = $userModel->getUserByPer('bi', 'business', 'read'); //权限范围内userIds
$whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件
$userIds = $whereData['userIds'];
4 years ago
if (!empty($whereData['between_time'][0])) unset($whereData['between_time'][1]);
4 years ago
$between_time = $whereData['between_time'];
$where['business.owner_user_id'] = array('in',$userIds);
4 years ago
$where['business.create_time'] = ['between', [$param['start_time'],$param['end_time']]];
4 years ago
if (!empty($param['is_end']) && $param['is_end'] == 1) $where['is_end'] = 1;
$count = db('crm_business')->alias('business')
->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left')
->where($where)->group('business.business_id')->count();
$sql = db('crm_business')->alias('business')
4 years ago
->field('business.business_id,business.customer_id,business.money,business.type_id,business.status_id,business.deal_date,business.create_user_id,business.owner_user_id,business.is_end')
4 years ago
->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left')
->where($where)
->limit(($page - 1) * $limit, $limit)
->order(['money' => 'DESC'])
->group('business.business_id')
->select();
4 years ago
return ['dataCount' => $count, 'list' => $sql];
4 years ago
}
}