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

99 lines
2.5 KiB

4 years ago
  1. <?php
  2. namespace App\AdminAgent\Extensions\Grid;
  3. use App\Models\AgentProduct;
  4. use App\Models\DemandBidding;
  5. use App\Models\DemandProduct;
  6. use App\Traits\DemandTraits;
  7. use Dcat\Admin\Grid\RowAction;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Log;
  12. /**
  13. * 供应商审核
  14. * Class AuditSupplier
  15. * @package App\Admin\Extensions\Grid
  16. */
  17. class ChooseDemand extends RowAction
  18. {
  19. private $id;
  20. public function __construct($biddingId = '')
  21. {
  22. parent::__construct('选中竞标');
  23. $this->id = $biddingId;
  24. $this->title = '选中竞标';
  25. }
  26. protected function html()
  27. {
  28. $class = 'btn btn-sm btn-success';
  29. $this->appendHtmlAttribute('class', $class);
  30. $this->defaultHtmlAttribute('href', 'javascript:;');
  31. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  32. }
  33. public function handle(Request $request)
  34. {
  35. $demandBiddingId = request('bidding_id',0);
  36. $demandBidding = DemandBidding::find($demandBiddingId);
  37. if (empty($demandBidding)) {
  38. return false;
  39. }
  40. $demand = \App\Models\Demand::find($demandBidding->demand_id);
  41. if (empty($demand)) {
  42. return false;
  43. }
  44. DB::beginTransaction();
  45. try {
  46. $demandBidding->state = 1;
  47. $demandBidding->save();
  48. //改变订单状态
  49. $demand->bidding_id = $demandBidding->id;
  50. $demand->bidding_user_id = $demandBidding->bidding_user_id;
  51. $demand->state = DemandTraits::$stateKey[1];
  52. $demand->save();
  53. //将产品绑给代理商
  54. $demandProduct = DemandProduct::find($demand->demand_product_id);
  55. $product = new Product();
  56. $product->supplier_id = $demandProduct->supplier_id;
  57. $product->category_id = $demandProduct->category_id;
  58. $product->title = $demandProduct->title;
  59. $product->price = $demandBidding->price;
  60. $product->original_price = $demandBidding->price;
  61. $product->pictures = $demandProduct->pictures;
  62. $product->stock = $demand->stock;
  63. $product->know = $demandProduct->know;
  64. $product->content = $demandProduct->content;
  65. $product->agent_id = $demandBidding->bidding_user_id;
  66. $product->save();
  67. $demand->product_id = $product->id;
  68. $demand->save();
  69. DB::commit();
  70. return $this->response()->success("选中竞标成功")->refresh();
  71. } catch (\Exception $e) {
  72. Log::error('选中竞标失败::'.$e->getTraceAsString());
  73. DB::rollBack();
  74. return $this->response()->error($e->getMessage());
  75. }
  76. }
  77. public function confirm()
  78. {
  79. return ['确定要选中该竞标吗?', ''];
  80. }
  81. public function parameters()
  82. {
  83. return ['bidding_id' => $this->id];
  84. }
  85. }