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

52 lines
1.3 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. ->orderBy('supplier_date')
  21. ->get([
  22. 'id AS product_spec_id',
  23. 'name AS supplier_name',
  24. 'date AS supplier_date',
  25. 'price AS supplier_price',
  26. 'stock AS supplier_stock',
  27. ])->toArray();
  28. } else {
  29. $spec = ProductSpec::where('product_id', $id)
  30. ->orderBy('supplier_date')
  31. ->get([
  32. 'id AS product_spec_id',
  33. 'name AS supplier_name',
  34. 'date AS supplier_date',
  35. 'price AS supplier_price',
  36. 'stock AS supplier_stock',
  37. ])->toArray();
  38. }
  39. return $this->response()->data($spec);
  40. }
  41. public function form()
  42. {
  43. $this->hidden('product_id');
  44. $this->hidden('agent_product_id');
  45. }
  46. }