dao = $dao; } /** * Common: 公共搜索模型 * Author: wu-hui * Time: 2024/04/10 18:15 * @param $search * @return \app\common\model\store\Point */ public function getSearchModel($search){ return $this->dao->searchList($search); } /** * Common: 列表获取 * Author: wu-hui * Time: 2024/04/10 18:18 * @param array $params * @param int $page * @param int $limit * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList(array $params,int $page,int $limit):array{ $query = $this->dao->searchList($params); $count = $query->count(); $list = $query->page($page,$limit)->select()->toArray(); return compact('count','list'); } /** * Common: 添加 / 编辑 * Author: wu-hui * Time: 2024/04/10 18:17 * @param $params * @throws \think\db\exception\DbException */ public function editInfo($params){ $data = [ "mer_id" => $params['mer_id'], "mer_take_name" => $params['mer_take_name'], "mer_take_phone" => $params['mer_take_phone'], "mer_take_location" => implode(',',$params['mer_take_location']), "mer_take_address" => $params['mer_take_address'], "mer_take_day" => implode(',',$params['mer_take_day']), "mer_take_time" => implode(',',$params['mer_take_time']) ]; // 判断:是否符合条件 if(empty($params['mer_take_name'])) throw new ValidateException('请输入提货点名称'); if(empty($params['mer_take_phone'])) throw new ValidateException('请输入提货点手机号'); if(empty($params['mer_take_location'])) throw new ValidateException('请选择经纬度'); if(empty($params['mer_take_address'])) throw new ValidateException('请输入提货点详细地址'); if(empty($params['mer_take_day'])) throw new ValidateException('请选择营业日期'); if(empty($params['mer_take_time'])) throw new ValidateException('请选择营业时间'); // 判断:是否已经存在 $isHas = $this->getSearchModel([]) ->where('mer_take_name',$params['mer_take_name']) ->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ $query->where('id','<>',(int)$params['id']); })->value('id'); if($isHas > 0) throw new ValidateException('提货点已经存在'); // 操作 if((int)$params['id'] > 0) $this->dao->update((int)$params['id'], $data);// 编辑 else $this->dao->create($data);// 添加 } /** * Common: 移动端获取总平台提货点配置信息 * Author: wu-hui * Time: 2024/04/11 10:14 * @param int $useId * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getUseInfo(int $useId = 0):array{ $list = $this->getSearchModel([])->withoutField('create_time,update_time')->select()->toArray(); if(count($list) == 1) $config = $list[0] ?? []; else $config = $useId > 0 ? (array_column($list, null, 'id')[$useId] ?? []) : []; return compact('list', 'config'); } }