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

86 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminAgent\Extensions\Grid;
  3. use App\Models\AgentProduct;
  4. use App\Models\DemandBidding;
  5. use App\Traits\DemandTraits;
  6. use Dcat\Admin\Grid\RowAction;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. /**
  11. * 供应商审核
  12. * Class AuditSupplier
  13. * @package App\Admin\Extensions\Grid
  14. */
  15. class ChooseDemand extends RowAction
  16. {
  17. private $id;
  18. public function __construct($biddingId = '')
  19. {
  20. parent::__construct('选中竞标');
  21. $this->id = $biddingId;
  22. $this->title = '选中竞标';
  23. }
  24. protected function html()
  25. {
  26. $class = 'btn btn-sm btn-success';
  27. $this->appendHtmlAttribute('class', $class);
  28. $this->defaultHtmlAttribute('href', 'javascript:;');
  29. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  30. }
  31. public function handle(Request $request)
  32. {
  33. $demandBiddingId = request('bidding_id',0);
  34. $demandBidding = DemandBidding::find($demandBiddingId);
  35. if (empty($demandBidding)) {
  36. return $this->response()->error('订单异常');
  37. }
  38. $demand = \App\Models\Demand::find($demandBidding->demand_id);
  39. if (empty($demand)) {
  40. return $this->response()->error('订单异常');
  41. }
  42. DB::beginTransaction();
  43. try {
  44. $demandBidding->state = 1;
  45. $demandBidding->save();
  46. //改变订单状态
  47. $demand->bidding_id = $demandBidding->id;
  48. $demand->bidding_user_id = $demandBidding->bidding_user_id;
  49. $demand->state = DemandTraits::$stateKey[1];
  50. $demand->save();
  51. //如果是地接类型 绑定地接到订单
  52. if ($demand->bidding_user_type == DemandTraits::$col[2]){
  53. $agentProduct = AgentProduct::find($demand->agent_product_id);
  54. $agentProduct->guide_id = $demandBidding->bidding_user_id;
  55. $agentProduct->guide_price = $demandBidding->price;
  56. $agentProduct->save();
  57. }
  58. DB::commit();
  59. return $this->response()->success("选中竞标成功")->refresh();
  60. } catch (\Exception $e) {
  61. Log::error('选中竞标失败::'.$e->getTraceAsString());
  62. DB::rollBack();
  63. return $this->response()->error($e->getMessage());
  64. }
  65. }
  66. public function confirm()
  67. {
  68. return ['确定要选中该竞标吗?', ''];
  69. }
  70. public function parameters()
  71. {
  72. return ['bidding_id' => $this->id];
  73. }
  74. }