PreController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. *
  5. * User: king/QQ:995265288
  6. * Date: 2018/7/27 下午4:09
  7. * Email: livsyitian@163.com
  8. */
  9. namespace app\backend\modules\withdraw\controllers;
  10. use app\backend\models\Withdraw;
  11. use app\common\components\BaseController;
  12. use app\common\exceptions\ShopException;
  13. abstract class PreController extends BaseController
  14. {
  15. /**
  16. * @var Withdraw
  17. */
  18. protected $withdrawModel;
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. $this->withdrawModel = $this->getWithdrawModel();
  23. }
  24. /**
  25. * 相关验证
  26. *
  27. * @param Withdraw $withdrawModel
  28. * @return ShopException
  29. */
  30. abstract function validatorWithdrawModel($withdrawModel);
  31. /**
  32. * 获取 withdrawModel
  33. *
  34. * @return Withdraw
  35. * @throws ShopException
  36. */
  37. protected function getWithdrawModel()
  38. {
  39. $withdraw_id = $this->getPostWithdrawId();
  40. $withdrawModel = Withdraw::find($withdraw_id);
  41. if (!$withdrawModel) {
  42. throw new ShopException('数据不存在或已被删除!');
  43. }
  44. $this->validatorWithdrawModel($withdrawModel);
  45. return $withdrawModel;
  46. }
  47. /**
  48. * 获取 POST 提交的ID主键
  49. *
  50. * @return int
  51. * @throws ShopException
  52. */
  53. protected function getPostWithdrawId()
  54. {
  55. $withdraw_id = \YunShop::request()->id;
  56. if (empty($withdraw_id)) {
  57. throw new ShopException('数据错误,请重试!');
  58. }
  59. return $withdraw_id;
  60. }
  61. }