123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace app\api\validate;
- use think\facade\Db;
- use think\Validate;
- //商品模块验证器
- class GoodValidate extends Validate
- {
- //验证规则
- protected $rule = [
- //基础信息
- 'good_name|商品名称' => 'require|max:255',
- 'tax|税点' => 'require|number|between:0,100',
- 'cat_id|分类ID' => 'require|number|gt:0|checkCatId:',
- 'companyNo|业务公司编码' => 'require|alphaNum|length:18|checkCompanyNo:',
- 'unit_id|单位ID' => 'require|number|gt:0|checkUnitId:',
- 'brand_id|品牌ID' => 'require|number|gt:0|checkBrandId:',
- 'exclusive_id|专属类型' => 'require|number|gt:0|checkExclusiveId:',//is_exclusive
- 'weight|商品重量' => 'require|float|max:999999999999.999',
- 'good_type|类型' => 'require|in:1,2',//1定制,2常规
- 'moq|定制起订量' => 'requireIf:good_type,1|number|gt:0|elt:999999999',
- 'customized|定制工期' => 'requireIf:good_type,1|number|gt:0|elt:999999999',
- 'after_sales|售后说明' => 'require|max:20000',
- 'good_remark|商品备注' => 'require|max:20000',
- 'craft_desc|工艺说明' => 'max:20000',
- //包装信息
- 'packing_way|包装方式' => 'require|max:255',
- 'packing_spec|装箱规格' => 'require|max:255',
- 'packing_weight|装箱重量' => 'require|float|max:9999999999999.99',
- 'packing_size|装箱尺寸' => 'require|max:255',
- 'good_size|商品尺寸' => 'require|max:255',
- 'good_bar|商品条形码' => 'max:255',
- 'packing_list|包装清单' => 'require|max:255',
- //规格信息
- 'speclist|规格列表' => 'require|array|max:100',//[{"id":"","spec_id":"60","spec_value_id":"17","is_del":"0"}]
- //发货信息
- 'delivery_place|发货地' => 'require|array|length:3',//130000,130300,130304
- 'supply_area|供货区域' => 'require|number|in:1,2',
- 'delivery_day|物流时间' => 'require|number|max:999999999',
- 'origin_place|产地' => 'require|array|length:3',//130000,130300,130304
- 'lead_time|供货周期' => 'number|max:999999999',
- 'sample_day|调样周期' => 'number|max:999999999',
- //图片信息
- 'good_thumb_img|商品缩略图' => 'require|max:255|url',
- 'good_img|商品主图' => 'require|array|length:3,10',
- 'good_info_img|详情介绍' => 'require|array|max:10',
- //固定与阶梯成本
- 'demo_fee|打样费' => 'require|float|max:99999999.99',
- 'open_fee|开模费' => 'require|float|max:99999999.99',
- 'sample_fee|调样费' => 'require|number|float|max:99999999.99',
- 'market_price|市场价' => 'require|number|float|max:99999999.99',
- 'good_ladder|阶梯列表' => 'require|array|max:100',//[{"id":"","min_num":"20","nake_fee":"21","cost_fee":"22","delivery_fee":"23","cert_fee":"24","mark_fee":"25","package_fee":"26","other_fee":"27","is_del":"0"}]
- //其他场景下的规则
- 'page|页码' => 'require|number|gt:0',
- 'size|每页数量' => 'require|number|gt:0|elt:100',
- 'spuCode|商品编码' => 'require|alphaNum|length:19',
- 'start|开始时间' => 'date',
- 'end|结束时间' => 'date',
- ];
- //创建商品
- public function sceneCreateGood()
- {
- return $this
- ->only([
- 'good_name',//商品名称
- 'tax',//税点
- 'cat_id',//分类ID
- 'companyNo',//业务公司编码
- 'unit_id',//单位ID
- 'brand_id',//品牌ID
- 'exclusive_id',//专属类型
- 'weight',//商品重量
- 'good_type',//类型
- 'moq',//定制起订量
- 'customized',//定制工期
- 'after_sales',//售后说明
- 'good_remark',//商品备注
- 'craft_desc',//工艺说明
- 'packing_way',//包装方式
- 'packing_spec',//装箱规格
- 'packing_weight',//装箱重量
- 'packing_size',//装箱尺寸
- 'good_size',//商品尺寸
- 'good_bar',//商品条形码
- 'packing_list',//包装清单
- 'speclist',//规格列表
- 'delivery_place',//发货地
- 'supply_area',//供货区域
- 'delivery_day',//物流时间
- 'origin_place',//产地
- 'lead_time',//供货周期
- 'sample_day',//调样周期
- 'good_thumb_img',//商品缩略图
- 'good_img',//商品主图
- 'good_info_img',//详情介绍
- 'demo_fee',//打样费
- 'open_fee',//开模费
- 'sample_fee',//调样费
- 'market_price',//市场价
- 'good_ladder',//阶梯列表
- ])
- ->remove('page', true)//true,移除所有规则
- ->remove('size', true)
- ->remove('spuCode', true)
- ->remove('start', true)
- ->remove('end', true);
- }
- //查询商品
- public function sceneSelectGood()
- {
- return $this->only(['page', 'size', 'good_name', 'spuCode', 'cat_id', 'brand_id', 'start', 'end'])
- ->remove('good_name', ['require'])
- ->remove('spuCode', ['require', 'length'])
- ->remove('cat_id', ['require'])
- ->remove('brand_id', ['require']);
- }
- //修改商品基础信息
- public function sceneUpdateGoodBasicsInfo()
- {
- return $this
- ->only(['spuCode', 'good_name', 'tax', 'cat_id', 'companyNo', 'unit_id', 'brand_id', 'exclusive_id', 'weight', 'good_type', 'moq', 'customized', 'after_sales', 'good_remark', 'craft_desc', 'packing_way', 'packing_spec', 'packing_weight', 'packing_size', 'good_size', 'good_bar', 'packing_list', 'speclist', 'delivery_place', 'delivery_day', 'origin_place', 'lead_time', 'sample_day', 'good_thumb_img', 'good_img', 'good_info_img', 'supply_area'])
- ->remove('brand_id', ['require'])
- ->remove('good_size', ['require'])
- ->remove('good_bar', ['require'])
- ->remove('speclist', ['require'])
- ->remove('lead_time', ['require'])
- ->remove('sample_day', ['require']);
- }
- //修改商品价格信息
- 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 : '该专属类型不存在';
- }
- }
|