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.
203 lines
5.7 KiB
203 lines
5.7 KiB
<?php
|
|
|
|
namespace app\admin\controller\qingdong\product;
|
|
|
|
use addons\qingdong\model\Delivery;
|
|
use addons\qingdong\model\DeliveryProduct;
|
|
use addons\qingdong\model\Goods;
|
|
use addons\qingdong\model\InstockProduct;
|
|
use addons\qingdong\model\ProductPart;
|
|
use addons\qingdong\model\Producttype;
|
|
use addons\qingdong\model\ProductWarehouse;
|
|
use addons\qingdong\model\Staff;
|
|
use app\admin\controller\qingdong\Base;
|
|
use app\admin\model\AuthGroup;
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Csv;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
|
use think\Db;
|
|
use think\Exception;
|
|
/**
|
|
* 产品列表
|
|
* 操作文档:https://doc.fastadmin.net/qingdong
|
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html
|
|
* 售后微信:qingdong_crm
|
|
*/
|
|
|
|
class Company extends Base
|
|
{
|
|
protected $relationSearch = true;
|
|
protected $searchFields = 'id,name';
|
|
/**
|
|
* @var \addons\qingdong\model\Product
|
|
*/
|
|
protected $model = null;
|
|
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \addons\qingdong\model\Company();
|
|
}
|
|
|
|
|
|
/**
|
|
* 产品列表
|
|
*/
|
|
public function index()
|
|
{
|
|
//设置过滤方法
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
|
|
//获取所有权限
|
|
$list2 = Db::name('auth_group')->where('status','=','normal')->select();
|
|
$roles = array_column($list2,'name','id');
|
|
|
|
if ($this->request->isAjax()) {
|
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
$sort="id";
|
|
$order="desc";
|
|
|
|
//负责人为空
|
|
$list = $this->model->where($where)->where('is_pay','=',1)->order($sort, $order)->paginate($limit);
|
|
$row=$list->items();
|
|
foreach ($row as $k => $v) {
|
|
$v['group_name'] = $roles[$v['group_id']]??'';
|
|
$row[$k] = $v;
|
|
}
|
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
return json($result);
|
|
}
|
|
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
|
|
/**
|
|
* 添加产品
|
|
*/
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$params = $this->request->post("row/a");
|
|
if ($params) {
|
|
|
|
$params = $this->preExcludeFields($params);
|
|
//查询权限等级是否已存在
|
|
$count = $this->model->where("name","=",$params['name'])->count();
|
|
if($count>0){
|
|
$this->error("企业名称已存在!!");
|
|
}
|
|
$result = false;
|
|
Db::startTrans();
|
|
try {
|
|
$result = $this->model->allowField(true)->save($params);
|
|
Db::commit();
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
}
|
|
if ($result !== false) {
|
|
$this->success();
|
|
} else {
|
|
$this->error(__('No rows were inserted'));
|
|
}
|
|
}
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
}
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
|
|
/**
|
|
* 修改产品
|
|
*/
|
|
public function edit($ids = null)
|
|
{
|
|
$map['id'] = $ids??CID;
|
|
if ($this->request->isAjax()) {
|
|
$params = $this->request->post('row/a');
|
|
$params = $this->preExcludeFields($params);
|
|
|
|
//查询权限等级是否已存在
|
|
$count = $this->model->where("name","=",$params['name'])->where("id","neq",$ids)->count();
|
|
if($count>0){
|
|
$this->error("企业名称已存在!!");
|
|
}
|
|
|
|
$result = false;
|
|
Db::startTrans();
|
|
try {
|
|
$result = $this->model->allowField(true)->update($params, $map);
|
|
Db::commit();
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
}
|
|
if ($result !== false) {
|
|
$this->success('修改成功');
|
|
} else {
|
|
$this->error('修改失败');
|
|
}
|
|
}
|
|
$data = $this->model->where($map)->find();
|
|
|
|
|
|
//获取所有权限
|
|
$list2 = Db::name('auth_group')->where('status','=','normal')->select();
|
|
$roles = array_column($list2,'name','id');
|
|
|
|
$data['group_name'] = $roles[$data['group_id']]??'';
|
|
$data['expire_time_str'] = isset($data['expire_time']) && $data['expire_time']>0 ? date('Y-m-d',$data['expire_time']):'-';
|
|
|
|
$this->view->assign("row", $data);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
|
|
/**
|
|
* 产品详情
|
|
*/
|
|
public function detail($ids = null)
|
|
{
|
|
$row = $this->model->get($ids);
|
|
$this->assign('row', $row);
|
|
$this->assign('ids', $ids);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 删除产品
|
|
*/
|
|
public function del($ids = "")
|
|
{
|
|
if (!$this->request->isPost()) {
|
|
$this->error(__("Invalid parameters"));
|
|
}
|
|
$ids = $ids ? $ids : $this->request->post("ids");
|
|
$row = $this->model->get($ids);
|
|
$this->modelValidate = true;
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
$row->delete();
|
|
$this->success();
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取产品分类
|
|
*/
|
|
public function get_group(){
|
|
|
|
$countrys = AuthGroup::where('status','=','normal')->field('id,name')->order('id desc')->select();
|
|
return json(['list' => $countrys, 'total' => count($countrys)]);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|