diff --git a/app/adminapi/controller/marketing/MarketingStatisticsController.php b/app/adminapi/controller/marketing/MarketingStatisticsController.php index 7f60746ec..49e71ba92 100644 --- a/app/adminapi/controller/marketing/MarketingStatisticsController.php +++ b/app/adminapi/controller/marketing/MarketingStatisticsController.php @@ -3,12 +3,22 @@ namespace app\adminapi\controller\marketing; use app\adminapi\controller\BaseAdminController; - use app\common\model\dict\DictData; +use app\adminapi\logic\marketing\MarketingStatisticsLogic; +use app\common\model\dict\DictData; use app\common\model\marketing\MarketingContract; use app\common\model\marketing\MarketingCustom; class MarketingStatisticsController extends BaseAdminController { + + public function index(){ + $date=$this->request->get('date',''); + $where=[]; + $time = getDay($date); + $res=MarketingStatisticsLogic::marketingStatistics($where,$time); + return $this->data($res); + } + public function custom(){ $year = $this->request->get('year',date('Y')); //总客户数 diff --git a/app/adminapi/logic/marketing/MarketingStatisticsLogic.php b/app/adminapi/logic/marketing/MarketingStatisticsLogic.php new file mode 100644 index 000000000..a5d0dbb3b --- /dev/null +++ b/app/adminapi/logic/marketing/MarketingStatisticsLogic.php @@ -0,0 +1,77 @@ + $datearr[0], 'end_time' => $datearr[1]]); + $marketingContract=new MarketingContract(); + // //统计主合同 + $total_contract_type_0=$marketingContract->ContractTypeStatistics(['contract_type'=>0],$time,'sum'); + $total_contract_type_0_value=$marketingContract->ContractTypeStatistics(['contract_type'=>0],$time,'group','create_time'); + $data[]=[ + 'title' => '主合同', + 'desc' => '', + 'total_money' => $total_contract_type_0, + 'value' => $total_contract_type_0_value['y'], + 'type' => 1, + ]; + // //统计框架协议 + $total_contract_type_1=$marketingContract->ContractTypeStatistics(['contract_type'=>1],$time,'sum'); + $total_contract_type_1_value=$marketingContract->ContractTypeStatistics(['contract_type'=>1],$time,'group','create_time'); + $data[]=[ + 'title' => '框架协议', + 'desc' => '', + 'total_money' => $total_contract_type_1, + 'value' => $total_contract_type_1_value['y'], + 'type' => 1, + ]; + // //统计补充协议 + $total_contract_type_2=$marketingContract->ContractTypeStatistics(['contract_type'=>2],$time,'sum'); + $total_contract_type_2_value=$marketingContract->ContractTypeStatistics(['contract_type'=>2],$time,'group','create_time'); + $data[]=[ + 'title' => '补充协议', + 'desc' => '', + 'total_money' => $total_contract_type_2, + 'value' => $total_contract_type_2_value['y'], + 'type' => 1, + ]; + //统计客户 + $total_custom=MarketingCustom::count(); + $data[]=[ + 'title' => '客户总数', + 'desc' => '', + 'total_money' => $total_custom, + 'value' => [], + 'type' => 1, + ]; + //业务性质 + $business_nature = DictData::where('type_value', 'cost_consultation_business_nature')->column('name', 'value'); + foreach($business_nature as $key=>$value){ + $count=$marketingContract->ContractTypeStatistics(['business_nature'=>$key],$time,'sum'); + $y_value=$marketingContract->ContractTypeStatistics(['business_nature'=>$key],$time,'group','create_time'); + $data[] = [ + 'title' => $value, + 'desc' => '', + 'total_money' => $count, + 'value' => $y_value['y'], + 'type' => 1, + ]; + } + + return $data; + } +} diff --git a/app/common.php b/app/common.php index 250772c4c..badbc8578 100755 --- a/app/common.php +++ b/app/common.php @@ -1,9 +1,9 @@ = 0 ? true : false; } @@ -78,7 +78,7 @@ function compare_php(string $version) : bool * @author 段誉 * @date 2021/12/28 18:27 */ -function check_dir_write(string $dir = '') : bool +function check_dir_write(string $dir = ''): bool { $route = root_path() . '/' . $dir; return is_writable($route); @@ -271,7 +271,7 @@ function get_no_prefix_table_name($tableName) * @author 段誉 * @date 2023/2/23 11:35 */ -function generate_sn($table, $field, $prefix = '', $randSuffixLength = 4, $pool = []) : string +function generate_sn($table, $field, $prefix = '', $randSuffixLength = 4, $pool = []): string { $suffix = ''; for ($i = 0; $i < $randSuffixLength; $i++) { @@ -308,113 +308,208 @@ function format_amount($float) function group_by($array, $key): array { - $result = []; - foreach ($array as $item) { - $result[$item[$key]][] = $item; - } - return $result; + $result = []; + foreach ($array as $item) { + $result[$item[$key]][] = $item; + } + return $result; } function buildTree($items, $parentField, $parentId = 0): array { - $tree = []; - foreach ($items as $item) { - if ($item[$parentField] == $parentId) { - $children = buildTree($items, $parentField, $item['id']); - if ($children) { - $item['children'] = $children; - } - $tree[] = $item; - } - } - return $tree; + $tree = []; + foreach ($items as $item) { + if ($item[$parentField] == $parentId) { + $children = buildTree($items, $parentField, $item['id']); + if ($children) { + $item['children'] = $children; + } + $tree[] = $item; + } + } + return $tree; } function getAncestors($categoryId, $categoryTable): array { - $parentIds = []; - foreach ($categoryTable as $item) { - if ($item['id'] == $categoryId && $item['pid'] != 0) { - $parentIds[] = $item['pid']; - // 递归调用自身,将父类ID作为参数传入 - $newParentIds = getAncestors($item['pid'],$categoryTable); - $parentIds = array_merge($parentIds, $newParentIds); - } - } - - return $parentIds ; + $parentIds = []; + foreach ($categoryTable as $item) { + if ($item['id'] == $categoryId && $item['pid'] != 0) { + $parentIds[] = $item['pid']; + // 递归调用自身,将父类ID作为参数传入 + $newParentIds = getAncestors($item['pid'], $categoryTable); + $parentIds = array_merge($parentIds, $newParentIds); + } + } + + return $parentIds; } //数据唯一编码 function data_unique_code($str): string { - //质量检查单-20231215-0001 - return $str.'-'.date('Ymd',time()).'-'.mt_rand(100000, 999999); + //质量检查单-20231215-0001 + return $str . '-' . date('Ymd', time()) . '-' . mt_rand(100000, 999999); } -function daysBetweenDates($start_date,$end_date): bool|int +function daysBetweenDates($start_date, $end_date): bool|int { - $start = new DateTime($start_date); - $end = new DateTime($end_date); - $interval = $start->diff($end); - return $interval->days; + $start = new DateTime($start_date); + $end = new DateTime($end_date); + $interval = $start->diff($end); + return $interval->days; } -function addApprove($title,$content_id,$content_model,$path,$flow_id,$create_user_id) +function addApprove($title, $content_id, $content_model, $path, $flow_id, $create_user_id) { - $createUser = Admin::field('name,dept_id')->where('id',$create_user_id)->findOrEmpty(); - //获取审批流程信息 - $flowData = Flow::where('id',$flow_id)->findOrEmpty(); - Db::startTrans(); - try { - //添加审批内容 - $approveRes = FlowApprove::create([ - 'title' => $title, - 'content_id' => $content_id, - 'content_model' => $content_model, - 'path' => $path, - 'flow_id' => $flow_id, - 'create_user' => $create_user_id, - 'check_status' => 0, - ]); - $flowStepData = []; - foreach($flowData['flow_list'] as $k=>$v){ - $flowStepData[] = [ - 'approve_id' => $approveRes->id, - 'flow_name' => $flowData['check_type'] == 1 ? '' : $v['flow_step'], - 'flow_step' => $flowData['check_type'] == 1 ? $v['flow_step'] : 0, - 'flow_user' => implode(',',$v['flow_user']), - 'sort' => $k+1, - 'is_active' => $k==0 ? 1 : 0, - ]; - } - array_unshift($flowStepData, [ - 'approve_id' => $approveRes->id, - 'flow_name' => '', - 'flow_step' => 0, - 'flow_user' => 0, - 'sort' => 0, - 'is_active' => 0, - ]); - //添加审批步骤 - foreach($flowStepData as $v){ - FlowStep::create($v); - } - //添加审批记录 - FlowRecord::create([ - 'approve_id' => $approveRes->id, - 'step_id' => 0, - 'check_user_id' => 0, - 'check_time' => time(), - 'status' => 0, - 'title' => $createUser['name'].'提交了此申请', - 'content' => '提交申请', - 'is_invalid' => 0 - ]); - Db::commit(); - return $approveRes->id; - } catch (\Exception $e) { - Db::rollback(); - return false; - } + $createUser = Admin::field('name,dept_id')->where('id', $create_user_id)->findOrEmpty(); + //获取审批流程信息 + $flowData = Flow::where('id', $flow_id)->findOrEmpty(); + Db::startTrans(); + try { + //添加审批内容 + $approveRes = FlowApprove::create([ + 'title' => $title, + 'content_id' => $content_id, + 'content_model' => $content_model, + 'path' => $path, + 'flow_id' => $flow_id, + 'create_user' => $create_user_id, + 'check_status' => 0, + ]); + $flowStepData = []; + foreach ($flowData['flow_list'] as $k => $v) { + $flowStepData[] = [ + 'approve_id' => $approveRes->id, + 'flow_name' => $flowData['check_type'] == 1 ? '' : $v['flow_step'], + 'flow_step' => $flowData['check_type'] == 1 ? $v['flow_step'] : 0, + 'flow_user' => implode(',', $v['flow_user']), + 'sort' => $k + 1, + 'is_active' => $k == 0 ? 1 : 0, + ]; + } + array_unshift($flowStepData, [ + 'approve_id' => $approveRes->id, + 'flow_name' => '', + 'flow_step' => 0, + 'flow_user' => 0, + 'sort' => 0, + 'is_active' => 0, + ]); + //添加审批步骤 + foreach ($flowStepData as $v) { + FlowStep::create($v); + } + //添加审批记录 + FlowRecord::create([ + 'approve_id' => $approveRes->id, + 'step_id' => 0, + 'check_user_id' => 0, + 'check_time' => time(), + 'status' => 0, + 'title' => $createUser['name'] . '提交了此申请', + 'content' => '提交申请', + 'is_invalid' => 0 + ]); + Db::commit(); + return $approveRes->id; + } catch (\Exception $e) { + Db::rollback(); + return false; + } +} + +/** + * 搜索时间转换 + * @param $timeKey + * @param false $isNum + * @return array + * @throws \Exception + */ +function TimeConvert($timeKey, $isNum = false) +{ + switch ($timeKey) { + case "today": + $data['start_time'] = date('Y-m-d 00:00:00', time()); + $data['end_time'] = date('Y-m-d 23:59:59', time()); + $data['days'] = 1; + break; + case "yestoday": + $data['start_time'] = date('Y-m-d 00:00:00', strtotime('-1 day')); + $data['end_time'] = date('Y-m-d 23:59:59', strtotime('-1 day')); + $data['days'] = 1; + break; + case "last_month": + $data['start_time'] = date('Y-m-01 00:00:00', strtotime('-1 month')); + $data['end_time'] = date('Y-m-t 23:59:59', strtotime('-1 month')); + $data['days'] = 30; + break; + case "month": + $data['start_time'] = $month_start_time = date('Y-m-01 00:00:00', strtotime(date("Y-m-d"))); + $data['end_time'] = date('Y-m-d 23:59:59', strtotime("$month_start_time +1 month -1 day")); + $data['days'] = 30; + break; + case "year": + $data['start_time'] = date('Y-01-01 00:00:00', time()); + $data['end_time'] = date('Y-12-t 23:59:59', time()); + $data['days'] = 365; + break; + case "last_year": + $data['start_time'] = date('Y-01-01 00:00:00', strtotime('-1 year')); + $data['end_time'] = date('Y-12-t 23:59:59', strtotime('-1 year')); + $data['days'] = 365; + break; + case 30: + case 15: + case 7: + if (!$isNum) { + $data['start_time'] = date("Y-m-d 00:00:00", strtotime("-$timeKey day")); + $data['end_time'] = date('Y-m-d 23:59:59', time()); + $data['days'] = $timeKey; + } else { + $day = $timeKey * 2; + $data['start_time'] = date("Y-m-d 00:00:00", strtotime("-$day day")); + $data['end_time'] = date("Y-m-d 23:59:59", strtotime("-$timeKey day")); + $data['days'] = $timeKey; + } + break; + default: + $datetime_start = new \DateTime($timeKey['start_time']); + $datetime_end = new \DateTime($timeKey['end_time']); + $days = $datetime_start->diff($datetime_end)->days; + $days = $days > 0 ? $days : 1; + if (!$isNum) { + $data['start_time'] = $timeKey['start_time']; + $data['end_time'] = $timeKey['end_time']; + $data['days'] = $days; + } else { + $data['start_time'] = date("Y-m-d 00:00:00", strtotime("-$days day")); + $data['end_time'] = $timeKey['start_time']; + $data['days'] = $days; + } + } + return $data; +} + +/** + * 格式化时间 + * @param $time + * @return string + */ +function getDay($time) +{ + if (strstr($time, '-') !== false) { + [$startTime, $endTime] = explode('-', $time); + if (!$startTime && !$endTime) { + return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); + } else { + if ($startTime == $endTime) { + return $startTime . '-' . $endTime . ' 23:59:59'; + } else { + return $startTime . '-' . $endTime; + } + } + } else { + return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); + } } diff --git a/app/common/model/BaseModel.php b/app/common/model/BaseModel.php index 29fac96cb..6d288a7c9 100755 --- a/app/common/model/BaseModel.php +++ b/app/common/model/BaseModel.php @@ -11,53 +11,151 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - namespace app\common\model; - - use app\common\model\dict\DictData; - use app\common\service\FileService; - use think\Model; - + +namespace app\common\model; + +use app\common\model\dict\DictData; +use app\common\service\FileService; +use think\Model; + +/** + * 基础模型 + * Class BaseModel + * @package app\common\model + */ +class BaseModel extends Model +{ /** - * 基础模型 - * Class BaseModel - * @package app\common\model + * @notes 公共处理图片,补全路径 + * @param $value + * @return string + * @author 张无忌 + * @date 2021/9/10 11:02 */ - class BaseModel extends Model + public function getImageAttr($value) { - /** - * @notes 公共处理图片,补全路径 - * @param $value - * @return string - * @author 张无忌 - * @date 2021/9/10 11:02 - */ - public function getImageAttr($value) - { - return trim($value) ? FileService::getFileUrl($value) : ''; + return trim($value) ? FileService::getFileUrl($value) : ''; + } + + /** + * @notes 公共图片处理,去除图片域名 + * @param $value + * @return mixed|string + * @author 张无忌 + * @date 2021/9/10 11:04 + */ + public function setImageAttr($value) + { + return trim($value) ? FileService::setFileUrl($value) : ''; + } + + public function getAnnexAttr($value) + { + return !empty($value) ? json_decode($value, true) : ''; + } + + public function getApproveCheckStatusTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'check_status')->column('name', 'value'); + return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : '待审核'; + } + + /** + * 曲线统计 + * @param $time + * @param $type + * @param $timeType + * @return mixed + */ + public function getCurveData($where, $time, $str, string $group = 'create_time') + { + return $this->where($where) + ->when(isset($time), function ($query) use ($time, $str, $group) { + $query->whereBetweenTime($group, $time['start_time'], $time['end_time']); + if ($time['days'] == 1) { + $timeUinx = "%H"; + } elseif ($time['days'] == 30) { + $timeUinx = "%Y-%m-%d"; + } elseif ($time['days'] == 365) { + $timeUinx = "%Y-%m"; + } elseif ($time['days'] > 1 && $time['days'] < 30) { + $timeUinx = "%Y-%m-%d"; + } elseif ($time['days'] > 30 && $time['days'] < 365) { + $timeUinx = "%Y-%m"; + } else { + $timeUinx = "%Y-%m"; + } + $query->field("$str as number,FROM_UNIXTIME($group, '$timeUinx') as time"); + $query->group("FROM_UNIXTIME($group, '$timeUinx')"); + }) + ->order("$group ASC")->select()->toArray(); + } + + /** + * 处理Y坐标数据 + * @param array $data + * @param array $timeKey + * @return array + * @throws \Exception + */ + public function trendYdata(array $data, array $timeKey) + { + $hourMoney = array(); + $timeData = array(); + //获取日期之间的天数 + $getDayRange = function ($date, $timeKey) { + $datearr = []; + $stime = strtotime($timeKey['start_time']); + $etime = strtotime($timeKey['end_time']); + while ($stime <= $etime) { + $datearr['x'][] = date($date, $stime); + $datearr['y'][] = date($date, $stime); + $stime = $stime + 86400; + } + return $datearr; + }; + //获取日期之间的月份 + $getMonthRange = function ($date, $timeKey) { + $datearr = []; + $stime = date('Y-m-d', strtotime($timeKey['start_time'])); + $etime = date('Y-m-d', strtotime($timeKey['end_time'])); + $start = new \DateTime($stime); + $end = new \DateTime($etime); + $interval = \DateInterval::createFromDateString('1 month'); + $period = new \DatePeriod($start, $interval, $end); + foreach ($period as $dt) { + $datearr['x'][] = $dt->format($date); + $datearr['y'][] = $dt->format($date); + } + return $datearr; + }; + if ($timeKey['days'] == 1) { + for ($i = 0; $i <= 24; $i++) { + $timeData['x'][] = (string)($i < 10 ? ('0' . $i) : $i); + $timeData['y'][] = $i < 10 ? ('0' . $i) : $i; + //$timeData['y'][] = $i < 10 ? ('0' . $i . ":00") : $i . ":00"; + //$timeData['x'][] = $i < 10 ? ('0' . $i . ":00") : $i . ":00"; + } + } elseif ($timeKey['days'] == 30) { + $timeData = $getDayRange('Y-m-d', $timeKey); + } elseif ($timeKey['days'] == 365) { + $timeData = $getMonthRange('Y-m', $timeKey); + } elseif ($timeKey['days'] > 1 && $timeKey['days'] < 30) { + $timeData = $getDayRange('Y-m-d', $timeKey); + } elseif ($timeKey['days'] > 30 && $timeKey['days'] < 365) { + $timeData = $getMonthRange('Y-m', $timeKey); } - - /** - * @notes 公共图片处理,去除图片域名 - * @param $value - * @return mixed|string - * @author 张无忌 - * @date 2021/9/10 11:04 - */ - public function setImageAttr($value) - { - return trim($value) ? FileService::setFileUrl($value) : ''; + if ($data) { + $hourMoney = array_column($data, 'number', 'time'); } - - public function getAnnexAttr($value) - { - return !empty($value) ? json_decode($value, true) : ''; + $y = array(); + foreach ($timeData['y'] as $k => $v) { + if (array_key_exists($v, $hourMoney)) { + $y[$v] = $hourMoney[$v]; + } else { + $y[$v] = 0; + } } - - public function getApproveCheckStatusTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'check_status')->column('name', 'value'); - return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : '待审核'; - } - - } \ No newline at end of file + return ['x' => $timeData['x'], 'y' => $y]; + } +} diff --git a/app/common/model/marketing/MarketingContract.php b/app/common/model/marketing/MarketingContract.php index 3f99b7295..1808c6f98 100644 --- a/app/common/model/marketing/MarketingContract.php +++ b/app/common/model/marketing/MarketingContract.php @@ -11,140 +11,163 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - namespace app\common\model\marketing; - - - use app\common\model\BaseModel; - use app\common\model\dict\DictData; - use think\model\concern\SoftDelete; - - - /** - * 市场经营--合同信息模型 - * Class MarketingContract - * @package app\common\model\marketing - */ - class MarketingContract extends BaseModel - { - use SoftDelete; - - protected $name = 'marketing_contract'; - protected $deleteTime = 'delete_time'; - - public function getContractTypeTextAttr($value, $data): string - { - $arr = [0 => '主合同', 1 => '框架协议', 2 => '补充协议']; - return $arr[$data['contract_type']]; - } - - public function getBusinessNatureTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_business_nature')->column('name', 'value'); - return !empty($data['business_nature']) ? $dict[$data['business_nature']] : ''; - } - - public function getIndustryNatureTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_industry_nature')->column('name', 'value'); - return !empty($data['industry_nature']) ? $dict[$data['industry_nature']] : ''; - } - - public function getFundSourcesTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'money_source')->column('name', 'value'); - return !empty($data['fund_sources']) ? $dict[$data['fund_sources']] : ''; - } - - public function getConstAreaTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_const_area')->column('name', 'value'); - return !empty($data['const_area']) ? $dict[$data['const_area']] : ''; - } - - public function getAgreementNatureTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'agreement_nature')->column('name', 'value'); - return !empty($data['agreement_nature']) ? $dict[$data['agreement_nature']] : ''; - } - - public function getImplementMethodTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_way')->column('name', 'value'); - return !empty($data['implement_method']) ? $dict[$data['implement_method']] : ''; - } - - public function getFileTypeTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_file_type')->column('name', 'value'); - return !empty($data['file_type']) ? $dict[$data['file_type']] : ''; - } - - public function getSealNameTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_seal_name')->column('name', 'value'); - return !empty($data['seal_name']) ? $dict[$data['seal_name']] : ''; - } - - public function getApproveCheckStatusTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'cost_consultation_seal_name')->column('name', 'value'); - return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : ''; - } - - public function getIsLimitTextAttr($value, $data): string - { - $arr = [0 => '否', 1 => '是']; - return $arr[$data['is_limit']]; - } - - public function getPlanceSealTextAttr($value, $data): string - { - $arr = [0 => '否', 1 => '是']; - return $arr[$data['plance_seal']]; - } - - public function getReviewStatusTextAttr($value, $data): string - { - if($data['contract_type'] == 0){ - $arr = [0 => '待移交', 1 => '已移交']; - return $arr[$data['review_status']]; - }else{ - return '不可移交'; - } +namespace app\common\model\marketing; + + +use app\common\model\BaseModel; +use app\common\model\dict\DictData; +use think\model\concern\SoftDelete; + + +/** + * 市场经营--合同信息模型 + * Class MarketingContract + * @package app\common\model\marketing + */ +class MarketingContract extends BaseModel +{ + use SoftDelete; + + protected $name = 'marketing_contract'; + protected $deleteTime = 'delete_time'; + + public function getContractTypeTextAttr($value, $data): string + { + $arr = [0 => '主合同', 1 => '框架协议', 2 => '补充协议']; + return $arr[$data['contract_type']]; + } + + public function getBusinessNatureTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_business_nature')->column('name', 'value'); + return !empty($data['business_nature']) ? $dict[$data['business_nature']] : ''; + } + + public function getIndustryNatureTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_industry_nature')->column('name', 'value'); + return !empty($data['industry_nature']) ? $dict[$data['industry_nature']] : ''; + } + + public function getFundSourcesTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'money_source')->column('name', 'value'); + return !empty($data['fund_sources']) ? $dict[$data['fund_sources']] : ''; + } + + public function getConstAreaTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_const_area')->column('name', 'value'); + return !empty($data['const_area']) ? $dict[$data['const_area']] : ''; + } + + public function getAgreementNatureTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'agreement_nature')->column('name', 'value'); + return !empty($data['agreement_nature']) ? $dict[$data['agreement_nature']] : ''; + } + + public function getImplementMethodTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_way')->column('name', 'value'); + return !empty($data['implement_method']) ? $dict[$data['implement_method']] : ''; + } + + public function getFileTypeTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_file_type')->column('name', 'value'); + return !empty($data['file_type']) ? $dict[$data['file_type']] : ''; + } + + public function getSealNameTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_seal_name')->column('name', 'value'); + return !empty($data['seal_name']) ? $dict[$data['seal_name']] : ''; + } + + public function getApproveCheckStatusTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'cost_consultation_seal_name')->column('name', 'value'); + return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : ''; + } + + public function getIsLimitTextAttr($value, $data): string + { + $arr = [0 => '否', 1 => '是']; + return $arr[$data['is_limit']]; + } + + public function getPlanceSealTextAttr($value, $data): string + { + $arr = [0 => '否', 1 => '是']; + return $arr[$data['plance_seal']]; + } + + public function getReviewStatusTextAttr($value, $data): string + { + if ($data['contract_type'] == 0) { + $arr = [0 => '待移交', 1 => '已移交']; + return $arr[$data['review_status']]; + } else { + return '不可移交'; } - - public function getStatusTextAttr($value, $data): string - { - $arr = [0 => '待立项', 1 => '已立项']; - return $arr[$data['reflux_status']]; + } + + public function getStatusTextAttr($value, $data): string + { + $arr = [0 => '待立项', 1 => '已立项']; + return $arr[$data['reflux_status']]; + } + + public function getRefluxStatusTextAttr($value, $data): string + { + $arr = [0 => '未回流', 1 => '已回流']; + return $arr[$data['reflux_status']]; + } + + + public function getStartDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getEndDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getPerformanceMoneyExpirationTimeAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getSendDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + /** + * 统计合同类型 + */ + public function ContractTypeStatistics($where, $time, string $selectType, string $group = "") + { + switch ($selectType) { + case "sum": + $totalMoney = $this->where($where)->when(isset($time), function ($query) use ($time) { + $query->whereBetweenTime('create_time', strtotime($time['start_time']), strtotime($time['end_time'])); + })->count(); + break; + case "group": + $totalMoney = $this->getCurveData($where, $time, 'count(id)', $group); + break; + default: + throw new \Exception('getOrderTotalMoney:selectType参数错误'); } - - public function getRefluxStatusTextAttr($value, $data): string - { - $arr = [0 => '未回流', 1 => '已回流']; - return $arr[$data['reflux_status']]; + + if ($group) { + $totalMoney = $this->trendYdata((array)$totalMoney, $time); } - - - public function getStartDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getEndDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getPerformanceMoneyExpirationTimeAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - - public function getSendDateAttr($value): string - { - return !empty($value) ? date('Y-m-d', $value) : ''; - } - } \ No newline at end of file + return $totalMoney; + } +} diff --git a/app/common/model/marketing/MarketingCustom.php b/app/common/model/marketing/MarketingCustom.php index 478205239..87877a06f 100644 --- a/app/common/model/marketing/MarketingCustom.php +++ b/app/common/model/marketing/MarketingCustom.php @@ -11,36 +11,36 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - namespace app\common\model\marketing; - - - use app\common\model\BaseModel; - use app\common\model\dict\DictData; - use think\model\concern\SoftDelete; - - - /** - * 市场经营--客户信息模型 - * Class MarketingCustom - * @package app\common\model\marketing - */ - class MarketingCustom extends BaseModel + +namespace app\common\model\marketing; + + +use app\common\model\BaseModel; +use app\common\model\dict\DictData; +use think\model\concern\SoftDelete; + + +/** + * 市场经营--客户信息模型 + * Class MarketingCustom + * @package app\common\model\marketing + */ +class MarketingCustom extends BaseModel +{ + use SoftDelete; + + protected $name = 'marketing_custom'; + protected $deleteTime = 'delete_time'; + + public function getImportantLevelTextAttr($value, $data) { - use SoftDelete; - - protected $name = 'marketing_custom'; - protected $deleteTime = 'delete_time'; - - public function getImportantLevelTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'custom_important_level')->column('name', 'value'); - return !empty($data['important_level']) ? $dict[$data['important_level']] : ''; - } - - public function getCategoryTextAttr($value, $data) - { - $dict = DictData::where('type_value', 'custom_category')->column('name', 'value'); - return !empty($data['category']) ? $dict[$data['category']] : ''; - } - } \ No newline at end of file + $dict = DictData::where('type_value', 'custom_important_level')->column('name', 'value'); + return !empty($data['important_level']) ? $dict[$data['important_level']] : ''; + } + + public function getCategoryTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'custom_category')->column('name', 'value'); + return !empty($data['category']) ? $dict[$data['category']] : ''; + } +}