海南旅游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.

49 lines
1.2 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. if (!empty($input['agent_product_id'])) {
  16. $agent_spec = AgentProductSpec::where('agent_product_id', $input['agent_product_id'])
  17. ->pluck('product_spec_id')->toArray();
  18. $spec = ProductSpec::where('product_id', $id)
  19. ->whereNotIn('id', $agent_spec ?? [0])
  20. ->get([
  21. 'id AS product_spec_id',
  22. 'name AS supplier_name',
  23. 'date AS supplier_date',
  24. 'price AS supplier_price',
  25. 'stock AS supplier_stock',
  26. ])->toArray();
  27. } else {
  28. $spec = ProductSpec::where('product_id', $id)->get([
  29. 'id AS product_spec_id',
  30. 'name AS supplier_name',
  31. 'date AS supplier_date',
  32. 'price AS supplier_price',
  33. 'stock AS supplier_stock',
  34. ])->toArray();
  35. }
  36. return $this->response()->data($spec);
  37. }
  38. public function form()
  39. {
  40. $this->hidden('product_id');
  41. $this->hidden('agent_product_id');
  42. }
  43. }