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:',
- 'weight|商品重量' => 'require|float|max:999999999999.999',
- 'good_type|类型' => 'require|in: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',
-
- 'delivery_place|发货地' => 'require|array|length:3',
- 'supply_area|供货区域' => 'require|number|in:1,2',
- 'delivery_day|物流时间' => 'require|number|max:999999999',
- 'origin_place|产地' => 'require|array|length:3',
- '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',
-
- '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',
- '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',
- '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)
- ->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 : '该专属类型不存在';
- }
- }
|