diff --git a/app/common/model/Retail.php b/app/common/model/Retail.php index cd764bf8..802d986d 100644 --- a/app/common/model/Retail.php +++ b/app/common/model/Retail.php @@ -21,6 +21,15 @@ class Retail extends BaseModel // 定义主键 protected $pk = 'retail_price_id'; + // 开启自动写入时间戳 + protected $autoWriteTimestamp = true; + + // 创建时间字段 + protected $createTime = 'create_time'; + + // 更新时间字段 + protected $updateTime = 'update_time'; + } \ No newline at end of file diff --git a/app/store/controller/Retail.php b/app/store/controller/Retail.php new file mode 100644 index 00000000..e15d427e --- /dev/null +++ b/app/store/controller/Retail.php @@ -0,0 +1,99 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\controller; + +use think\response\Json; +use app\store\model\Retail as RetailModel; + +use function Symfony\Component\VarDumper\Dumper\esc; + +class Retail extends Controller +{ + + /** + * 查看所有会员售价 + * @return Json + */ + public function list(): Json + { + $where = []; + $type = $this->request->post('retailType'); + if ($type) { + $where['retail_type'] = $type; + } + // $model = new RetailModel(); + // $list = $model->getList($where); + $list = RetailModel::withoutGlobalScope()->where($where)->select(); + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:新增 + * @return Json + * + */ + public function add(): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = new RetailModel(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * @notes:编辑 + * @param int $retailPriceId + * @return Json + * @author: + */ + public function edit(int $retailPriceId): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = RetailModel::withoutGlobalScope()->where('retail_price_id', $retailPriceId)->find(); + if (!$model) { + return $this->renderError('找不到指定的数据'); + } + $data['update_time']=time(); + RetailModel::withoutGlobalScope()->where('retail_price_id', $retailPriceId)->update($data); + return $this->renderSuccess('编辑成功'); + + } + + /** + * @notes:删除 + * @param array $identityId + * @return Json + * @author: wanghousheng + */ + public function delete(array $retailPriceId): Json + { + $model = new RetailModel; + if ($model->remove($retailPriceId)) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError('删除失败'); + } + + + + + +} \ No newline at end of file diff --git a/app/store/model/Retail.php b/app/store/model/Retail.php new file mode 100644 index 00000000..b556759e --- /dev/null +++ b/app/store/model/Retail.php @@ -0,0 +1,72 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\Retail as RetailModel; + +class Retail extends RetailModel +{ + + public function getList(array $where) + { + return $this->where($where)->order('sort', 'asc')->select(); + } + + /** + * @notes:新增 + * @param $data + * @return bool + */ + public function add($data): bool + { + return $this->save($data); + } + + /** + * @notes:编辑 + * @param $data + * @return bool + */ + public function edit($data): bool + { + return $this->save($data) !== false; + } + + /** + * @notes:详情 + * @param $where + * @param array $with + * @return static|array|null + * @author: wanghousheng + */ + public static function detail($where, array $with = []) + { + return static::get($where, $with); + } + + /** + * @notes:删除 + * @param array $IdentityId + * @return bool + * @author: wanghousheng + */ + public function remove(array $retailPriceId): bool + { + if (static::whereIn('retail_price_id', $retailPriceId)->delete()) { + return true; + } + return false; + } + + +} \ No newline at end of file