GoodValidate.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\api\validate;
  3. use think\facade\Db;
  4. use think\Validate;
  5. //商品模块验证器
  6. class GoodValidate extends Validate
  7. {
  8. //验证规则
  9. protected $rule = [
  10. //基础信息
  11. 'good_name|商品名称' => 'require|max:255',
  12. 'tax|税点' => 'require|number|between:0,100',
  13. 'cat_id|分类ID' => 'require|number|gt:0|checkCatId:',
  14. 'companyNo|业务公司编码' => 'require|alphaNum|length:18|checkCompanyNo:',
  15. 'unit_id|单位ID' => 'require|number|gt:0|checkUnitId:',
  16. 'brand_id|品牌ID' => 'require|number|gt:0|checkBrandId:',
  17. 'exclusive_id|专属类型' => 'require|number|gt:0|checkExclusiveId:',//is_exclusive
  18. 'weight|商品重量' => 'require|float|max:999999999999.999',
  19. 'good_type|类型' => 'require|in:1,2',//1定制,2常规
  20. 'moq|定制起订量' => 'requireIf:good_type,1|number|gt:0|elt:999999999',
  21. 'customized|定制工期' => 'requireIf:good_type,1|number|gt:0|elt:999999999',
  22. 'after_sales|售后说明' => 'require|max:20000',
  23. 'good_remark|商品备注' => 'require|max:20000',
  24. 'craft_desc|工艺说明' => 'max:20000',
  25. //包装信息
  26. 'packing_way|包装方式' => 'require|max:255',
  27. 'packing_spec|装箱规格' => 'require|max:255',
  28. 'packing_weight|装箱重量' => 'require|float|max:9999999999999.99',
  29. 'packing_size|装箱尺寸' => 'require|max:255',
  30. 'good_size|商品尺寸' => 'require|max:255',
  31. 'good_bar|商品条形码' => 'max:255',
  32. 'packing_list|包装清单' => 'require|max:255',
  33. //规格信息
  34. 'speclist|规格列表' => 'require|array|max:100',//[{"id":"","spec_id":"60","spec_value_id":"17","is_del":"0"}]
  35. //发货信息
  36. 'delivery_place|发货地' => 'require|array|length:3',//130000,130300,130304
  37. 'supply_area|供货区域' => 'require|number|in:1,2',
  38. 'delivery_day|物流时间' => 'require|number|max:999999999',
  39. 'origin_place|产地' => 'require|array|length:3',//130000,130300,130304
  40. 'lead_time|供货周期' => 'number|max:999999999',
  41. 'sample_day|调样周期' => 'number|max:999999999',
  42. //图片信息
  43. 'good_thumb_img|商品缩略图' => 'require|max:255|url',
  44. 'good_img|商品主图' => 'require|array|length:3,10',
  45. 'good_info_img|详情介绍' => 'require|array|max:10',
  46. //固定与阶梯成本
  47. 'demo_fee|打样费' => 'require|float|max:99999999.99',
  48. 'open_fee|开模费' => 'require|float|max:99999999.99',
  49. 'sample_fee|调样费' => 'require|number|float|max:99999999.99',
  50. 'market_price|市场价' => 'require|number|float|max:99999999.99',
  51. '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"}]
  52. //其他场景下的规则
  53. 'page|页码' => 'require|number|gt:0',
  54. 'size|每页数量' => 'require|number|gt:0|elt:100',
  55. 'spuCode|商品编码' => 'require|alphaNum|length:19',
  56. 'start|开始时间' => 'date',
  57. 'end|结束时间' => 'date',
  58. ];
  59. //创建商品
  60. public function sceneCreateGood()
  61. {
  62. return $this
  63. ->only([
  64. 'good_name',//商品名称
  65. 'tax',//税点
  66. 'cat_id',//分类ID
  67. 'companyNo',//业务公司编码
  68. 'unit_id',//单位ID
  69. 'brand_id',//品牌ID
  70. 'exclusive_id',//专属类型
  71. 'weight',//商品重量
  72. 'good_type',//类型
  73. 'moq',//定制起订量
  74. 'customized',//定制工期
  75. 'after_sales',//售后说明
  76. 'good_remark',//商品备注
  77. 'craft_desc',//工艺说明
  78. 'packing_way',//包装方式
  79. 'packing_spec',//装箱规格
  80. 'packing_weight',//装箱重量
  81. 'packing_size',//装箱尺寸
  82. 'good_size',//商品尺寸
  83. 'good_bar',//商品条形码
  84. 'packing_list',//包装清单
  85. 'speclist',//规格列表
  86. 'delivery_place',//发货地
  87. 'supply_area',//供货区域
  88. 'delivery_day',//物流时间
  89. 'origin_place',//产地
  90. 'lead_time',//供货周期
  91. 'sample_day',//调样周期
  92. 'good_thumb_img',//商品缩略图
  93. 'good_img',//商品主图
  94. 'good_info_img',//详情介绍
  95. 'demo_fee',//打样费
  96. 'open_fee',//开模费
  97. 'sample_fee',//调样费
  98. 'market_price',//市场价
  99. 'good_ladder',//阶梯列表
  100. ])
  101. ->remove('page', true)//true,移除所有规则
  102. ->remove('size', true)
  103. ->remove('spuCode', true)
  104. ->remove('start', true)
  105. ->remove('end', true);
  106. }
  107. //查询商品
  108. public function sceneSelectGood()
  109. {
  110. return $this->only(['page', 'size', 'good_name', 'spuCode', 'cat_id', 'brand_id', 'start', 'end'])
  111. ->remove('good_name', ['require'])
  112. ->remove('spuCode', ['require', 'length'])
  113. ->remove('cat_id', ['require'])
  114. ->remove('brand_id', ['require']);
  115. }
  116. //修改商品基础信息
  117. public function sceneUpdateGoodBasicsInfo()
  118. {
  119. return $this
  120. ->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'])
  121. ->remove('brand_id', ['require'])
  122. ->remove('good_size', ['require'])
  123. ->remove('good_bar', ['require'])
  124. ->remove('speclist', ['require'])
  125. ->remove('lead_time', ['require'])
  126. ->remove('sample_day', ['require']);
  127. }
  128. //修改商品价格信息
  129. public function sceneUpdateGoodPriceInfo()
  130. {
  131. return $this->only(['spuCode', 'demo_fee', 'open_fee', 'sample_fee', 'market_price', 'good_ladder']);
  132. }
  133. //获取商品详情
  134. public function sceneGetGoodDetail()
  135. {
  136. return $this->only(['spuCode']);
  137. }
  138. //校验单位
  139. protected function checkUnitId($value)
  140. {
  141. return Db::connect('mysql_wsm')
  142. ->table('wsm_unit')
  143. ->field('id')
  144. ->where(['id' => $value, 'is_del' => 0])
  145. ->findOrEmpty() ? true : '该单位ID不存在';
  146. }
  147. //校验分类
  148. protected function checkCatId($value = '')
  149. {
  150. return Db::connect('mysql_wsm')
  151. ->table('wsm_cat')
  152. ->field('id')
  153. ->where(['id' => $value, 'is_del' => 0])
  154. ->findOrEmpty() ? true : '该分类ID不存在';
  155. }
  156. //校验品牌
  157. protected function checkBrandId($value = '')
  158. {
  159. return Db::connect('mysql_wsm')
  160. ->table('wsm_brand')
  161. ->field('id')
  162. ->where(['id' => $value, 'is_del' => 0])
  163. ->findOrEmpty() ? true : '该品牌ID不存在';
  164. }
  165. //校验业务公司
  166. protected function checkCompanyNo($value = '')
  167. {
  168. return Db::connect('mysql_wsm')
  169. ->table('wsm_business')
  170. ->field('id')
  171. ->where(['companyNo' => $value, 'is_del' => 0])
  172. ->findOrEmpty() ? true : '该业务公司不存在';
  173. }
  174. //校验专属类型
  175. protected function checkExclusiveId($value = '')
  176. {
  177. return Db::connect('mysql_wsm')
  178. ->table('wsm_exclusive')
  179. ->field('id')
  180. ->where(['id' => $value, 'is_del' => 0])
  181. ->findOrEmpty() ? true : '该专属类型不存在';
  182. }
  183. }