RefundAddressController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\Mch\client\controllers;
  3. use addons\Mch\common\models\MchRefundAddress;
  4. use common\enums\StatusEnum;
  5. use Yii;
  6. /**
  7. *
  8. * @Author bing
  9. * @DateTime 2021-08-16 13:12:44
  10. * @copyright: Copyright (c) 2020 广东七件事集团
  11. */
  12. class RefundAddressController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. /**
  16. * @Author bing
  17. * @DateTime 2021-08-20 14:49:55
  18. * @copyright: Copyright (c) 2020 广东七件事集团
  19. * @return void
  20. */
  21. public function actionIndex(){
  22. if (Yii::$app->request->isAjax) {
  23. $params = [
  24. 'where'=>[
  25. ['mall_id'=>$this->mall_id],
  26. ['mch_id'=>$this->mch_id],
  27. ['status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]],
  28. ],
  29. 'order'=>'id desc'
  30. ];
  31. $list = MchRefundAddress::listPage($params);
  32. if($list === false) return $this->error(MchRefundAddress::getStaticError());
  33. return $this->success('ok',$list);
  34. }
  35. return $this->render($this->action->id);
  36. }
  37. public function actionEdit()
  38. {
  39. $request = Yii::$app->request;
  40. if ($request->isAjax) {
  41. if ($request->isGet) {
  42. $id = Yii::$app->request->get('id', '');
  43. $data = MchRefundAddress::getOne([['id'=>$id],['mall_id'=>$this->mall_id],['mch_id'=>$this->mch_id]],true);
  44. return $this->success('操作成功', ['data'=>$data]);
  45. }
  46. try {
  47. if ($request->isPost) {
  48. $params = Yii::$app->request->post();
  49. $res = Yii::$app->services->validate->validate($params, [
  50. [['refund_name', 'name','mobile','address'], 'required'],
  51. [['id'], 'safe'],
  52. ]);
  53. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  54. $params['mall_id'] = $this->mall_id;
  55. $params['mch_id'] = $this->mch_id;
  56. $res = MchRefundAddress::setData($params);
  57. if ($res === false) return $this->error(MchRefundAddress::getStaticError());
  58. return $this->success('操作成功');
  59. }
  60. } catch (\Exception $e) {
  61. return $this->error($e->getMessage(), []);
  62. }
  63. }
  64. }
  65. /**
  66. * 删除
  67. * @param null $keyword
  68. * @param int $is_recycle
  69. * @return mixed|void
  70. */
  71. public function actionDel()
  72. {
  73. $request = Yii::$app->request;
  74. if ($request->isAjax) {
  75. if ($request->isGet) {
  76. $params = Yii::$app->request->get();
  77. $params['status'] = StatusEnum::DELETE;
  78. $params['mall_id'] = $this->mall_id;
  79. $params['mch_id'] = $this->mch_id;
  80. $res = MchRefundAddress::setData($params);
  81. if ($res === false) return $this->error(MchRefundAddress::getStaticError());
  82. return $this->success('操作成功');
  83. }
  84. }
  85. }
  86. }