GoodsMoreSpecLists.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\shop\validate\goods;
  20. use app\common\basics\Validate;
  21. use app\common\enum\FreightEnum;
  22. use app\common\model\Freight;
  23. class GoodsMoreSpecLists extends Validate
  24. {
  25. protected $rule = [
  26. 'market_price' => [ ],
  27. 'price' => 'require|egt:0.01|checkExpress',
  28. 'chengben_price' => [],
  29. 'stock' => 'require|integer|egt:0',
  30. 'weight' => [],
  31. 'volume' => [],
  32. ];
  33. protected $message = [
  34. 'market_price.require' => '请输入市场价',
  35. 'market_price.egt' => '市场价必须大于或等于0.01',
  36. 'price.require' => '请输入价格',
  37. 'price.egt' => '价格必须大于或等于0.01',
  38. 'chengben_price.require' => '请输入成本价',
  39. 'chengben_price.egt' => '成本价必须大于或等于0.01',
  40. 'stock.require' => '请输入库存',
  41. 'stock.integer' => '库存必须为整数',
  42. 'stock.egt' => '库存必须大于或等于0',
  43. 'weight.require' => '请输入重量',
  44. 'weight.egt' => '重量必须大于或等于0',
  45. 'volume.require' => '请输入体积',
  46. 'volume.egt' => '体积必须大于或等于0',
  47. ];
  48. function checkExpress($value, $rule, $data)
  49. {
  50. $express_type = input('express_type');
  51. // 运费模版
  52. if ($express_type != 3) {
  53. return true;
  54. }
  55. $freight = Freight::where('id', input('express_template_id/d'))->findOrEmpty();
  56. if (empty($freight['id'])) {
  57. return '运费模板不存在';
  58. }
  59. switch ($freight['charge_way']) {
  60. case FreightEnum::CHARGE_WAY_WEIGHT:
  61. if (empty($data['weight']) || $data['weight'] <= 0) {
  62. return '当前运费模板是按重量计算运费,规格:' . $data['spec_value_str'] .' 的重量必须大于0';
  63. }
  64. break;
  65. case FreightEnum::CHARGE_WAY_VOLUME:
  66. if (empty($data['volume']) || $data['volume'] <= 0) {
  67. return '当前运费模板是按体积计算运费,规格:' . $data['spec_value_str'] .' 的体积必须大于0';
  68. }
  69. break;
  70. default:
  71. break;
  72. }
  73. return true;
  74. }
  75. }