diff --git a/application/admin/controller/Coupons.php b/application/admin/controller/Coupons.php new file mode 100644 index 0000000..98120a7 --- /dev/null +++ b/application/admin/controller/Coupons.php @@ -0,0 +1,38 @@ +model = new \app\admin\model\Coupons; + $this->view->assign("discountTypeList", $this->model->getDiscountTypeList()); + $this->view->assign("statusList", $this->model->getStatusList()); + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + +} diff --git a/application/admin/controller/Item.php b/application/admin/controller/Item.php index a81d21a..f841937 100644 --- a/application/admin/controller/Item.php +++ b/application/admin/controller/Item.php @@ -38,16 +38,37 @@ class Item extends Backend { if ($this->request->isAjax()) { // 必须将结果集转换为数组 - $ruleList = \think\Db::name("item") - ->where('status',1) - ->field('id,pid,level,title,key_word,sort,status') - ->order('sort DESC,id ASC')->select(); + $search = request()->get('search') ?? false; +// dd($where); + $build = Db::name('item') + ->where('status',1); + if ($search){ + $build->where(function ($query) use ($search){ + $query->where('title','like','%'.$search.'%') + ->whereOr('key_word','like','%'.$search.'%'); + }); + } + + $ruleList = $build->field('id,pid,level,title,key_word,sort,status') +// ->order('sort','desc') +// ->fetchSql(true) + ->select(); + if ($search){ + $pids = array_column($ruleList,'pid') ; + $pidData = Db::name('item') + ->where('status',1)->whereIn('id',$pids) + ->field('id,pid,level,title,key_word,sort,status')->select(); + $ruleList = array_values(array_reduce(array_merge($ruleList,$pidData), function ($carry, $item) { + $carry[$item['id']] = $item; + return $carry; + }, [])); + } Tree::instance()->init($ruleList)->icon = [' ', ' ', ' ']; -// dd($ruleList); +// dd($ruleList); $this->itemdata = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); foreach ($this->itemdata as &$v) { - $v['status'] = $v['status'] ?'normal' : ''; + $v['status'] = $v['status'] ?'normal' : 'hidden'; } unset($v); diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 9e374fb..39efa57 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -3,6 +3,7 @@ namespace app\admin\controller; use app\common\controller\Backend; +use fast\Tree; use think\Db; use think\exception\PDOException; use think\exception\ValidateException; @@ -20,12 +21,77 @@ class Order extends Backend * @var \app\admin\model\Order */ protected $model = null; - + protected $sources = null; + protected $items = null; public function _initialize() { parent::_initialize(); $this->model = new \app\admin\model\Order; $this->view->assign("statusList", $this->model->getStatusList()); + + $sources = Db::name('source') + ->where('status',1) + ->field(['id','title','key_word','pid']) + ->order('pid','asc') + ->order('sort','desc') + ->select(); + $this->sources = $sources; + $filtered = array_filter($sources, function($item) { + return $item['pid'] == 0; + }); + + $pid_map = array_column($filtered,null,'id'); + $res = []; + foreach ($sources as $item){ + if ($item['pid'] != 0 && isset($pid_map[$item['pid']])){ + $res [] = [ + ...$item,'ptitle' => $pid_map[$item['pid']]['title'] + ]; + } + } +// dd($res); + +// Tree::instance()->init($sources); +// $data = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); +// dd($data); + + $items = Db::name('item') + ->where('status',1) + ->field(['id','title','key_word','pid']) + ->order('pid','asc') + ->order('sort','desc') + ->select(); + + $phones = Db::name('phones') + ->where('assigned_user',$this->auth->id) + ->field(['id','model','phone_number']) + ->select(); + + $this->items = $items; + $filtered = array_filter($items, function($item) { + return $item['pid'] == 0; + }); + + $pid_map = array_column($filtered,null,'id'); + $res_items = []; + foreach ($items as $item){ + if ($item['pid'] != 0 && isset($pid_map[$item['pid']])){ + $res_items [] = [ + ...$item,'ptitle' => $pid_map[$item['pid']]['title'] + ]; + } + } + + $coupons = Db::name('coupons') + ->where('status','active') + ->field(['id','code','description']) + ->select(); + + $this->view->assign("statusList", $this->model->getStatusList()); + $this->view->assign("sources", $res); + $this->view->assign("coupons", $coupons); + $this->view->assign("items", $res_items); + $this->view->assign("phones", $phones); //$this->view->assign("collectList", $this->model->getCollectList()); //$this->view->assign("dispatchTypeList", $this->model->getDispatchTypeList()); } @@ -52,10 +118,17 @@ class Order extends Backend } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model - ->field(['id','order_no','customer','tel','status','area_id','address', - 'source','source_uid','source','item_title','item_id', + ->field(['id','order_no','user_id','customer','tel','status','area_id','address', + 'source','source_shop','source_uid','source','item_title','item_id','work_tel_id', 'detail','remark','images','create_time','update_time']) ->where($where) + ->with(['user' => function($q){ + $q->field('id,nickname'); + },'area' => function($q){ + $q->field('id,area_code,merge_name'); + },'phone' => function($q){ + $q->field('id,model'); + }]) ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; @@ -86,7 +159,13 @@ class Order extends Backend $this->model->validateFailException()->validate($validate); } - $params['enter_admin_id'] = $this->auth->id; + $sources = $this->sources; + $items = $this->items; + $sources = array_column($sources,'title','id'); + $items = array_column($items,'title','id'); + $params['source_shop'] = $sources[$params['source']] ?? null; + $params['item_title'] = $items[$params['item_id']] ?? null; + $params['user_id'] = $this->auth->id; $params['status'] = 10; $params['order_no'] = $this->generateOrderNumber(); $params['create_time'] = date('Y-m-d H:i:s'); @@ -127,10 +206,27 @@ class Order extends Backend // 判断是否为POST请求,进行更新操作 if (request()->isPost()) { // 获取表单提交的数据 - $data = input('post.row/a'); - $data['update_time'] = date('Y-m-d H:i:s'); + $params = input('post.row/a'); + $params['update_time'] = date('Y-m-d H:i:s'); + $sources = $this->sources; + $sources = array_column($sources,'title','id'); +// $data['user_id'] = $this->auth->id; + $params['source_shop'] = $sources[$params['source']] ?? null; + + $sources = $this->sources; + $items = $this->items; + + $sources = array_column($sources,'title','id'); + $items = array_column($items,'title','id'); + + $params['source_shop'] = $sources[$params['source']] ?? null; + $params['item_title'] = $items[$params['item_id']] ?? null; + + $params['create_time'] = date('Y-m-d H:i:s'); + $params['update_time'] = date('Y-m-d H:i:s'); + // 更新订单信息 - $order->save($data); + $order->save($params); // 返回成功信息 $this->success('更新成功', 'index'); diff --git a/application/admin/controller/Phones.php b/application/admin/controller/Phones.php new file mode 100644 index 0000000..c5c7f44 --- /dev/null +++ b/application/admin/controller/Phones.php @@ -0,0 +1,160 @@ +model = new \app\admin\model\Phones; + + $users = Db::name('admin') +// ->where('status',1) + ->field(['id','nickname']) + ->select(); + $this->view->assign("statusList", $this->model->getStatusList()); + $this->view->assign("users", $users); + + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + + public function index() + { + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + //如果发送的来源是 Selectpage,则转发到 Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->where($where) + ->with(['user' => function($q){ + $q->field('id,nickname'); + }]) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } + + public function add() + { + if (false === $this->request->isPost()) { + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException()->validate($validate); + } + if ($params['assigned_user'] != 0){ + $params['status'] = 'assigned'; + $params['assigned_date'] = date('Y-m-d H:i:s'); + }else{ + $params['status'] = 'available'; + $params['assigned_date'] = null; + } + + + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + + public function edit($ids = null) + { + if (!$ids) { + if (request()->isPost()){ + $ids = input('id'); + if (!$ids){ + $this->error('缺少订单ID'); + } + }else{ + $this->error('缺少订单ID'); + } + } + + // 获取当前ID对应的订单信息 + $order = $this->model->get($ids); + if (!$order) { + $this->error('订单不存在'); + } + + // 判断是否为POST请求,进行更新操作 + if (request()->isPost()) { + // 获取表单提交的数据 + $data = input('post.row/a'); + + if ($data['assigned_user'] != 0){ + $data['status'] = 'assigned'; + $data['assigned_date'] = date('Y-m-d H:i:s'); + }else{ + $data['status'] = 'available'; + $data['assigned_date'] = null; + } + // 更新订单信息 + $order->save($data); + + // 返回成功信息 + $this->success('更新成功', 'index'); + } + // 将订单数据传递到视图 + $this->assign('row', $order); + + // 渲染编辑页面 + return $this->fetch(); + } + +} diff --git a/application/admin/controller/Source.php b/application/admin/controller/Source.php new file mode 100644 index 0000000..09e41be --- /dev/null +++ b/application/admin/controller/Source.php @@ -0,0 +1,237 @@ +model = new \app\admin\model\Source; + $this->view->assign("statusList", $this->model->getStatusList()); + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + public function index() + { + if ($this->request->isAjax()) { + // 必须将结果集转换为数组 + $search = request()->get('search') ?? false; +// dd($where); + $build = Db::name('source') + ->where('status',1); + if ($search){ + $build->where(function ($query) use ($search){ + $query->where('title','like','%'.$search.'%') + ->whereOr('key_word','like','%'.$search.'%'); + }); + } + + $ruleList = $build->field('id,pid,level,title,key_word,sort,status') +// ->order('sort','desc') +// ->fetchSql(true) + ->select(); + if ($search){ + $pids = array_column($ruleList,'pid') ; + $pidData = Db::name('source') + ->where('status',1)->whereIn('id',$pids) + ->field('id,pid,level,title,key_word,sort,status')->select(); + $ruleList = array_values(array_reduce(array_merge($ruleList,$pidData), function ($carry, $source) { + $carry[$source['id']] = $source; + return $carry; + }, [])); + } + + Tree::instance()->init($ruleList)->icon = [' ', ' ', ' ']; +// dd($ruleList); + $this->sourcedata = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); + foreach ($this->sourcedata as &$v) { + $v['status'] = $v['status'] ?'normal' : 'aqua'; + } + unset($v); + + $list = $this->sourcedata; + $total = count($this->sourcedata); + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch(); + } + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + public function add() + { + if (false === $this->request->isPost()) { + // 必须将结果集转换为数组 + $ruleList = \think\Db::name("source") + ->where('pid',0) + ->field('id,pid,level,title,key_word') + ->order('sort DESC,id ASC')->select(); + + Tree::instance()->init($ruleList)->icon = [' ', ' ', ' ']; +// dd($ruleList); + $this->sourcedata = Tree::instance()->getTreeList(Tree::instance() + ->getTreeArray(0), 'title'); + $sourcedata = [0 => __('None')]; + foreach ($this->sourcedata as $k => $v) { + $sourcedata[$v['id']] = $v['title']; + unset($v['spacer']); + } + unset($v); + + $this->view->assign('sourcedata', $sourcedata); + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException()->validate($validate); + } + + $pid = $params['pid']; + if ($pid > 0){ + $parent = $this->model->where('id',$pid)->find(); + if ($parent){ + $params['level'] = $parent->value('level') + 1; + } + }else{ + $params['level'] = 0; + } + + + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + + public function search(){ + + $keyword = request()->get('keyword'); + if (!$keyword){ + $this->success(data:[]); + }else{ + $data = model('source') + ->where('level','=',2) + ->where(function ($query)use ($keyword){ + $query->where('title','like','%'.$keyword.'%') + ->whereOr('key_word', 'like', "%{$keyword}%"); + }) + ->order('level','desc') + ->field('title,id,key_word') + ->limit(0,10) + ->select(); + $this->success(data:$data); + } + + } + + public function edit($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + if (false === $this->request->isPost()) { + // 必须将结果集转换为数组 + $ruleList = \think\Db::name("source") + ->where('pid',0) + ->field('id,pid,level,title,key_word') + ->order('sort DESC,id ASC')->select(); + + Tree::instance()->init($ruleList)->icon = [' ', ' ', ' ']; +// dd($ruleList); + $this->sourcedata = Tree::instance()->getTreeList(Tree::instance() + ->getTreeArray(0), 'title'); + $sourcedata = [0 => __('None')]; + foreach ($this->sourcedata as $k => $v) { + $sourcedata[$v['id']] = $v['title']; + unset($v['spacer']); + } + unset($v); + + $this->view->assign('sourcedata', $sourcedata); + $this->view->assign('row', $row); + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException()->validate($validate); + } + $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if (false === $result) { + $this->error(__('No rows were updated')); + } + $this->success(); + } + +} diff --git a/application/admin/lang/zh-cn/coupons.php b/application/admin/lang/zh-cn/coupons.php new file mode 100644 index 0000000..de9a13b --- /dev/null +++ b/application/admin/lang/zh-cn/coupons.php @@ -0,0 +1,20 @@ + '优惠码唯一标识', + 'Code' => '优惠码名称', + 'Description' => '优惠码描述', + 'Discount_type' => '折扣类型', + 'Min_order' => '最低消费金额', + 'Max_discount' => '最大优惠金额', + 'Status' => '状态', + 'Threshold' => '优惠门槛', + 'Discount_value' => '优惠金额', + 'Created_at' => '创建时间', + 'Updated_at' => '更新时间', + 'Percentage' => '百分比优惠', + + 'Fixed' => '固定优惠', + 'Active' => '可用', + 'Inactive' => '禁用', +]; diff --git a/application/admin/lang/zh-cn/order.php b/application/admin/lang/zh-cn/order.php index 23ce16d..2fc90ac 100644 --- a/application/admin/lang/zh-cn/order.php +++ b/application/admin/lang/zh-cn/order.php @@ -57,5 +57,6 @@ return [ 'Payment_time' => '付款时间', 'Finishe_time' => '完成时间', 'Dispatch_time' => '派单时间', - 'Delete_time' => '删除时间' + 'Delete_time' => '删除时间', + 'Coupons' => '优惠', ]; diff --git a/application/admin/lang/zh-cn/phones.php b/application/admin/lang/zh-cn/phones.php new file mode 100644 index 0000000..59af4f3 --- /dev/null +++ b/application/admin/lang/zh-cn/phones.php @@ -0,0 +1,10 @@ + '手机号码', + 'Model' => '型号', + 'Assigned_user' => '使用者', + 'Assigned_date' => '使用时期', + 'Available' => '空闲', + 'Assigned' => '已分配', +]; diff --git a/application/admin/lang/zh-cn/source.php b/application/admin/lang/zh-cn/source.php new file mode 100644 index 0000000..fd5908f --- /dev/null +++ b/application/admin/lang/zh-cn/source.php @@ -0,0 +1,16 @@ + 'ID', + 'Pid' => 'PID', + 'Level' => '层级', + 'Title' => '服务名称', + 'Key_word' => '关键字', + 'Image' => '图标', + 'Sort' => '排序', + 'Status' => '状态', + 'Status 1' => '启用', + 'Set status to 1'=> '设为启用', + 'Status 0' => '关闭', + 'Set status to 0'=> '设为关闭' +]; diff --git a/application/admin/model/Coupons.php b/application/admin/model/Coupons.php new file mode 100644 index 0000000..f3996dc --- /dev/null +++ b/application/admin/model/Coupons.php @@ -0,0 +1,63 @@ + __('Fixed'), 'percentage' => __('Percentage')]; + } + + public function getStatusList() + { + return ['active' => __('Active'), 'inactive' => __('Inactive')]; + } + + + public function getDiscountTypeTextAttr($value, $data) + { + $value = $value ?: ($data['discount_type'] ?? ''); + $list = $this->getDiscountTypeList(); + return $list[$value] ?? ''; + } + + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } + + + + +} diff --git a/application/admin/model/Order.php b/application/admin/model/Order.php index e626744..35be7c1 100644 --- a/application/admin/model/Order.php +++ b/application/admin/model/Order.php @@ -99,7 +99,14 @@ class Order extends Model } - public function admin(){ - return $this->belongsTo(Admin::class,'audit_admin_id',); + public function user(){ + return $this->belongsTo(Admin::class,'user_id',); + } + + public function area(){ + return $this->belongsTo(Area::class,'area_id','area_code'); + } + public function phone(){ + return $this->belongsTo(Phones::class,'work_tel_id',); } } diff --git a/application/admin/model/Phones.php b/application/admin/model/Phones.php new file mode 100644 index 0000000..6cbc532 --- /dev/null +++ b/application/admin/model/Phones.php @@ -0,0 +1,47 @@ + __('Available'), 'assigned' => __('Assigned')]; + } + + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } + + + + public function user(){ + return $this->belongsTo(Admin::class,'assigned_user'); + } +} diff --git a/application/admin/model/Source.php b/application/admin/model/Source.php new file mode 100644 index 0000000..8c5d186 --- /dev/null +++ b/application/admin/model/Source.php @@ -0,0 +1,49 @@ + __('Status 1'), '0' => __('Status 0')]; + } + + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } + + + + +} diff --git a/application/admin/validate/Coupons.php b/application/admin/validate/Coupons.php new file mode 100644 index 0000000..2a1b72b --- /dev/null +++ b/application/admin/validate/Coupons.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/validate/Phones.php b/application/admin/validate/Phones.php new file mode 100644 index 0000000..61a94e5 --- /dev/null +++ b/application/admin/validate/Phones.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/validate/Source.php b/application/admin/validate/Source.php new file mode 100644 index 0000000..bf63a14 --- /dev/null +++ b/application/admin/validate/Source.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/coupons/add.html b/application/admin/view/coupons/add.html new file mode 100644 index 0000000..cc2ac12 --- /dev/null +++ b/application/admin/view/coupons/add.html @@ -0,0 +1,81 @@ +
diff --git a/application/admin/view/coupons/edit.html b/application/admin/view/coupons/edit.html new file mode 100644 index 0000000..f500d2f --- /dev/null +++ b/application/admin/view/coupons/edit.html @@ -0,0 +1,81 @@ + diff --git a/application/admin/view/coupons/index.html b/application/admin/view/coupons/index.html new file mode 100644 index 0000000..8e5b965 --- /dev/null +++ b/application/admin/view/coupons/index.html @@ -0,0 +1,46 @@ +