123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\admin\validate;
- use app\model\GoodModel;
- use think\facade\Db;
- use think\Validate;
- //商品模块验证器
- class GoodValidate extends Validate
- {
- //验证规则
- protected $rule = [
- 'good_cover_img|商品封面图' => 'require|max:255|url',
- 'good_name|商品名称' => 'require|max:255',
- 'moq|销售起订量' => 'require|number|min:1|max:999999999',
- 'step|销售步长' => 'require|number|min:1|max:999999999',
- 'good_banner_img|商品轮播图' => 'require|array|min:1|max:100',
- 'good_img|商品详情图' => 'require|array|min:1|max:100',
- 'good_param|商品参数' => 'require|array|min:1|max:100',
- 'unit_id|单位id' => 'require|number|gt:0',
- 'good_remark|商品备注' => 'require|max:255',
- 'type|商品类型' => 'require|number|in:1,2'
- ];
- //创建商品
- public function sceneAdd()
- {
- return $this
- ->only([
- 'good_cover_img',
- 'good_name',
- 'moq',
- 'step',
- 'good_banner_img',
- 'good_img',
- 'good_param',
- 'unit_id',
- 'good_remark',
- 'type'
- ]);
- }
- //修改商品信息
- public function sceneEdit()
- {
- return $this->append('id|主键', 'require|number|gt:0');
- }
- //修改商品价格信息
- public function sceneUpdateGoodPriceInfo()
- {
- return $this->only(['spuCode', 'demo_fee', 'open_fee', 'sample_fee', 'market_price', 'good_ladder']);
- }
- //获取商品详情
- public function sceneGetGoodDetail()
- {
- return $this->only(['spuCode']);
- }
- //校验单位
- protected function checkUnitId($value)
- {
- return Db::connect('mysql_wsm')
- ->table('wsm_unit')
- ->field('id')
- ->where(['id' => $value, 'is_del' => 0])
- ->findOrEmpty() ? true : '该单位ID不存在';
- }
- //校验分类
- protected function checkCatId($value = '')
- {
- return Db::connect('mysql_wsm')
- ->table('wsm_cat')
- ->field('id')
- ->where(['id' => $value, 'is_del' => 0])
- ->findOrEmpty() ? true : '该分类ID不存在';
- }
- //校验品牌
- protected function checkBrandId($value = '')
- {
- return Db::connect('mysql_wsm')
- ->table('wsm_brand')
- ->field('id')
- ->where(['id' => $value, 'is_del' => 0])
- ->findOrEmpty() ? true : '该品牌ID不存在';
- }
- //校验业务公司
- protected function checkCompanyNo($value = '')
- {
- return Db::connect('mysql_wsm')
- ->table('wsm_business')
- ->field('id')
- ->where(['companyNo' => $value, 'is_del' => 0])
- ->findOrEmpty() ? true : '该业务公司不存在';
- }
- //校验专属类型
- protected function checkExclusiveId($value = '')
- {
- return Db::connect('mysql_wsm')
- ->table('wsm_exclusive')
- ->field('id')
- ->where(['id' => $value, 'is_del' => 0])
- ->findOrEmpty() ? true : '该专属类型不存在';
- }
- }
|