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

88 lines
2.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Grid;
  3. use App\Common\ProductStatus;
  4. use App\Models\IndustryProduct;
  5. use App\Models\Supplier;
  6. use App\Models\SystemSetting;
  7. use Dcat\Admin\Admin;
  8. use Dcat\Admin\Grid\RowAction;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\DB;
  11. /**
  12. * 行业产品审核
  13. * Class AuditAgentProduct
  14. * @package App\Admin\Extensions\Grid
  15. */
  16. class AuditIndustryProduct extends RowAction
  17. {
  18. private $action;
  19. public function __construct($title = null, $action = 1)
  20. {
  21. parent::__construct($title);
  22. $this->action = $action; //$action:1=通过;2=拒绝
  23. $this->title = $action == 1 ? '通过' : '拒绝';
  24. }
  25. protected function html()
  26. {
  27. $class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger';
  28. $this->appendHtmlAttribute('class', $class);
  29. $this->defaultHtmlAttribute('href', 'javascript:;');
  30. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  31. }
  32. public function handle(Request $request)
  33. {
  34. DB::beginTransaction();
  35. try {
  36. //修改产品状态
  37. $industry = IndustryProduct::find($this->getKey());
  38. $industry->status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
  39. $industry->save();
  40. //如果是通过,扣除交易金,如果拒绝返还冻结金额
  41. $single = SystemSetting::val('single', 'price'); //单人头交易金
  42. $supplier = Supplier::find(Admin::user()->id);
  43. $change_deposit = $single * $industry->stock * $industry->service_persons;
  44. if ($industry->status == ProductStatus::ON_SALE) {
  45. if ($supplier->deposit_normal < $change_deposit) {
  46. throw new \Exception('交易金不足,无法扣除');
  47. }
  48. $supplier->deposit_normal = $supplier->deposit_normal - $change_deposit;
  49. $supplier->deposit_frozen = $supplier->deposit_frozen + $change_deposit;
  50. $supplier->save();
  51. } /*else if ($industry->status == ProductStatus::REFUSE) { //拒绝无需处理
  52. if ($supplier->deposit_frozen < $change_deposit) {
  53. throw new \Exception('冻结金不足,无法扣除');
  54. }
  55. $supplier->deposit_normal = $supplier->deposit_normal + $change_deposit;
  56. $supplier->deposit_frozen = $supplier->deposit_frozen - $change_deposit;
  57. $supplier->save();
  58. }*/
  59. DB::commit();
  60. return $this->response()->success("审核成功")->refresh();
  61. } catch (\Exception $e) {
  62. DB::rollBack();
  63. return $this->response()->error($e->getMessage());
  64. }
  65. }
  66. public function confirm()
  67. {
  68. return ['确定要'.$this->title.'该产品吗?', ''];
  69. }
  70. public function parameters()
  71. {
  72. return ['action' => $this->action];
  73. }
  74. }