Filing.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\abutment\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. use app\abutment\logic\Filing as FilingLogic;
  6. class Filing extends HomeBaseController
  7. {
  8. //列表
  9. public function getList()
  10. {
  11. $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '', 'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => ''], 'post');
  12. $param['supplierNo'] = $this->request->user['supplierNo'];
  13. return FilingLogic::list($param);
  14. }
  15. //添加
  16. public function add()
  17. {
  18. $param = $this->request->only(['customerCode','companyName', 'num', 'is_determine_price', 'price' => 0, 'expect_service_proportion', 'expect_service', 'cgd_charge' => 0, 'brand_id', 'preservation_day', 'delivery_day', 'make_day', 'tax', 'unit_id', 'cat_id', 'spec_list' => [], 'good_name', 'origin_place', 'delivery_place', 'weight', 'supply_area', 'pay_way', 'gold_weight', 'noble_metal', 'config', 'other_config', 'remark', 'cost_desc', 'good_img'], 'post');
  19. $val = Validate::rule([
  20. 'customerCode|业务公司' => 'require|max:255',
  21. 'companyName|客户名称' => 'require|max:255',
  22. 'num|销售数量' => 'require|number|gt:0|lt:999999999',
  23. 'is_determine_price|是否确定售价' => 'require|number|in:1,0',
  24. 'price|销售价' => 'requireIf:is_determine_price,1|float|max:99999999.99',
  25. 'expect_service_proportion|期望服务费比例' => 'require|float|between:0,100',
  26. 'expect_service|期望服务费' => 'require|float|max:99999999.99',
  27. 'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
  28. 'brand_id|品牌' => 'require|number|gt:0',
  29. 'preservation_day|有效期' => 'require|number|max:999999999',
  30. 'delivery_day|物流时间' => 'require|number|max:999999999',
  31. 'make_day|生产工期' => 'require|number|max:999999999',
  32. 'tax|税点' => 'require|number|between:0,100',
  33. 'unit_id|单位' => 'require|number|gt:0',
  34. 'cat_id|分类' => 'require|number|gt:0',
  35. 'spec_list|规格类型' => 'array|max:100',
  36. 'good_name|商品名称' => 'require|max:255',
  37. 'origin_place|产地' => 'require|array|length:3',
  38. 'delivery_place|发货地' => 'require|array|length:3',
  39. 'weight|总重量' => 'require|float|max:99999999.99',
  40. 'supply_area|供货区域' => 'require|number|in:1,2',
  41. 'pay_way|付款方式' => 'require|number|in:0,1,2',
  42. 'remark|采购备注' => 'require|max:255',
  43. 'cost_desc|工艺说明' => 'max:255',
  44. 'good_img|商品图片' => 'require|array|max:10',
  45. ]);
  46. if (!$val->check($param)) return json_show(1004, $val->getError());
  47. //如果是贵金属的话,额外判断
  48. $cat=made($param['cat_id']);
  49. if(isset($cat[0]['id']) && $cat[0]['id']==6){
  50. $val_gold = Validate::rule([
  51. 'gold_weight|贵金属重量' => 'require|float|max:99999999.99',
  52. 'noble_metal|贵金属类型' => 'require|number|in:1,2,3',
  53. 'config|配置要求' => 'require|max:255',
  54. 'other_config|其他配置要求' => 'require|max:255',
  55. ]);
  56. if(!$val_gold->check($param)) return json_show(1004,$val_gold->getError());
  57. }
  58. $val2 = Validate::rule([
  59. 'spec_id|规格id' => 'require|number|gt:0',
  60. 'spec_value_id|规格值id' => 'require|number|gt:0',
  61. ]);
  62. $all_spec = Db::name('specs')
  63. ->whereIn('id', array_column($param['spec_list'], 'spec_id'))
  64. ->column('spec_name', 'id');
  65. $all_spec_value = Db::name('spec_value')
  66. ->whereIn('id', array_column($param['spec_list'], 'spec_value_id'))
  67. ->column('spec_value', 'id');
  68. foreach ($param['spec_list'] as &$spec_list) {
  69. if (!$val2->check($spec_list)) return json_show(1004, $val2->getError());
  70. $spec_list['spec_name'] = $all_spec[$spec_list['spec_id']] ?? '';
  71. $spec_list['spec_value_name'] = $all_spec_value[$spec_list['spec_value_id']] ?? '';
  72. }
  73. $param['supplierNo']= $this->request->user['supplierNo'];
  74. $param['supplierName']= $this->request->user['supplierName'];
  75. return FilingLogic::add($param);
  76. }
  77. //详情
  78. public function detail()
  79. {
  80. $param = $this->request->only(['id'], 'post');
  81. $param['supplierNo'] = $this->request->user['supplierNo'];
  82. return FilingLogic::detail($param);
  83. }
  84. //取消转单
  85. public function cancel()
  86. {
  87. $param = $this->request->only(['id'], 'post');
  88. $param['supplierNo'] = $this->request->user['supplierNo'];
  89. return FilingLogic::cancel($param);
  90. }
  91. //转单
  92. public function transfer()
  93. {
  94. $param = $this->request->only(['id', 'addr_list'], 'post');
  95. $val = Validate::rule([
  96. 'id' => 'require|number|gt:0',
  97. 'addr_list|收货地址' => 'require|array|max:100',
  98. ]);
  99. if (!$val->check($param)) return json_show(1004, $val->getError());
  100. $val2 = Validate::rule([
  101. 'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
  102. 'contactor|联系人' => 'require|max:255',
  103. 'mobile|联系电话' => 'require|mobile',
  104. 'addr_code|收货省市区编码' => 'require|array|length:3',
  105. 'addr|详细地址' => 'require|max:255',
  106. ]);
  107. foreach ($param['addr_list'] as $addr_list) {
  108. if (!$val2->check($addr_list)) return json_show(1004, $val2->getError());
  109. }
  110. $param['supplierNo'] = $this->request->user['supplierNo'];
  111. return FilingLogic::transfer($param);
  112. }
  113. }