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.
137 lines
4.7 KiB
137 lines
4.7 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace addon\zhjw\app\service\admin\sales;
|
|
|
|
use addon\zhjw\app\model\campuses\Campuses;
|
|
use addon\zhjw\app\model\classes\Classes;
|
|
use addon\zhjw\app\model\sales\Sales;
|
|
use addon\zhjw\app\model\staff\Staff;
|
|
use app\model\sys\SysArea;
|
|
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 销售管理服务层
|
|
* Class SalesService
|
|
* @package addon\zhjw\app\service\admin\sales
|
|
*/
|
|
class SalesService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new Sales();
|
|
}
|
|
|
|
/**
|
|
* 获取销售管理列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPage(array $where = [])
|
|
{
|
|
$field = 'id,student_phone,student_name,sex,age,school_name,grade,class_name,source_channel,customer_source,add_staff_id,get_staff_id,contact_name,province_id,city_id,district_id,full_address,community_name,customer_tags,create_time,update_time,is_deleted,created_by,created_role,updated_by,updated_role';
|
|
$order = 'id desc';
|
|
|
|
$search_model = $this->model->withSearch(["student_phone", "student_name", "sex", "age", "school_name", "grade", "class_name", "source_channel", "customer_source", "add_staff_id", "get_staff_id", "contact_name", "province_id", "city_id", "district_id", "community_name", "customer_tags", "create_time"], $where)->with(['staff', 'staff', 'sysArea', 'sysArea', 'sysArea'])->field($field)->order($order);
|
|
$list = $this->pageQuery($search_model);
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取销售管理信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,user_id,title,student_phone,campuses_id,class_id,is_status,student_name,sex,age,school_name,grade,class_name,source_channel,customer_source,add_staff_id,get_staff_id,contact_name,province_id,city_id,district_id,full_address,community_name,customer_tags,create_time,update_time,is_deleted,created_by,created_role,updated_by,updated_role';
|
|
|
|
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['staff', 'staff', 'sysArea', 'sysArea', 'sysArea'])->findOrEmpty()->toArray();
|
|
|
|
if(empty($info['customer_tags'])){
|
|
$info['customer_tags'] = [];
|
|
}else{
|
|
$info['customer_tags'] = explode(',',$info['customer_tags']);
|
|
}
|
|
|
|
if(!empty($info['province_id']) && !empty($info['city_id']) && !empty($info['district_id'])){
|
|
$info['full_address_id'] = [$info['province_id'],$info['city_id'],$info['district_id']];
|
|
}else{
|
|
$info['full_address_id'] = [];
|
|
}
|
|
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 添加销售管理
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
|
|
$campuses = new Campuses();
|
|
$calss = new Classes();
|
|
$data['school_name'] = $campuses->where(['id' => $data['campuses_id']])->value('name');
|
|
$data['class_name'] = $calss->where(['id' => $data['class_id']])->value('name');
|
|
$data['user_id'] = addMember($data);
|
|
$res = $this->model->create($data);
|
|
return $res->id;
|
|
}
|
|
|
|
/**
|
|
* 销售管理编辑
|
|
* @param int $id
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function edit(int $id, array $data)
|
|
{
|
|
$campuses = new Campuses();
|
|
$calss = new Classes();
|
|
$data['school_name'] = $campuses->where(['id' => $data['campuses_id']])->value('name');
|
|
$data['class_name'] = $calss->where(['id' => $data['class_id']])->value('name');
|
|
$this->model->where([['id', '=', $id]])->update($data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除销售管理
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function del(int $id)
|
|
{
|
|
$model = $this->model->where([['id', '=', $id]])->find();
|
|
$res = $model->delete();
|
|
return $res;
|
|
}
|
|
|
|
|
|
public function getStaffAll()
|
|
{
|
|
$staffModel = new Staff();
|
|
return $staffModel->select()->toArray();
|
|
}
|
|
|
|
|
|
public function getSysAreaAll()
|
|
{
|
|
$sysAreaModel = new SysArea();
|
|
return $sysAreaModel->select()->toArray();
|
|
}
|
|
|
|
|
|
}
|
|
|