海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. <?php
  2. namespace App\AdminAgent\Forms;
  3. use App\Models\AgentProductSpec;
  4. use App\Models\ProductSpec;
  5. use Dcat\Admin\Widgets\Form;
  6. use Dcat\Admin\Traits\LazyWidget;
  7. use Dcat\Admin\Contracts\LazyRenderable;
  8. class LoadSupplierSpec extends Form implements LazyRenderable
  9. {
  10. use LazyWidget;
  11. // 处理请求
  12. public function handle(array $input)
  13. {
  14. $id = $input['product_id'];
  15. $spec = ProductSpec::where('product_id', $id);
  16. if (!empty($input['agent_product_id'])) {
  17. $agent_spec = AgentProductSpec::where('agent_product_id', $input['agent_product_id'])
  18. ->pluck('product_spec_id')->toArray();
  19. if ($agent_spec) {
  20. $spec = $spec->whereNotIn('id', $agent_spec);
  21. }
  22. }
  23. $spec = $spec->orderBy('name')->orderBy('supplier_date')
  24. ->get([
  25. 'id AS product_spec_id',
  26. 'name AS supplier_name',
  27. 'date AS supplier_date',
  28. 'original_price AS supplier_original_price',
  29. 'price AS supplier_price',
  30. 'cost_price AS supplier_cost_price',
  31. 'stock AS supplier_stock',
  32. ])->toArray();
  33. return $this->response()->data($spec);
  34. }
  35. public function form()
  36. {
  37. $this->hidden('product_id');
  38. $this->hidden('agent_product_id');
  39. }
  40. }