ClerkController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace addons\Happiness\client\controllers;
  3. use addons\Happiness\common\service\ClerkService;
  4. use Yii;
  5. use Exception;
  6. class ClerkController extends BaseController
  7. {
  8. public $enableCsrfValidation = false;
  9. //核销员管理
  10. public function actionIndex()
  11. {
  12. $request = Yii::$app->request;
  13. if ($request->isAjax && $request->isGet) {
  14. try {
  15. $get = $request->get();
  16. $res = Yii::$app->services->validate->validate($get, [
  17. [['user_id', 'page', 'limit'], 'integer'],
  18. [['keyword'], 'string'],
  19. ]);
  20. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  21. $get['store_id'] = $this->store_id;
  22. $list = (new ClerkService(['mall_id' => $this->mall_id]))->getClerkMemberList($get);
  23. return $this->success('获取成功', $list);
  24. } catch (\Exception $e) {
  25. return $this->error($e->getMessage());
  26. }
  27. }
  28. return $this->render($this->action->id);
  29. }
  30. public function actionSearchUser()
  31. {
  32. $request = Yii::$app->request;
  33. if ($request->isAjax && $request->isGet) {
  34. try {
  35. $get = $request->get();
  36. $res = Yii::$app->services->validate->validate($get, [
  37. [['keyword'], 'string'],
  38. ]);
  39. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  40. $list = (new ClerkService(['mall_id' => $this->mall_id]))->searchUser($get);
  41. return $this->success('获取成功', $list);
  42. } catch (\Exception $e) {
  43. return $this->error($e->getMessage());
  44. }
  45. }
  46. }
  47. //添加核销员
  48. public function actionEdit()
  49. {
  50. $request = Yii::$app->request;
  51. if ($request->isAjax) {
  52. if ($request->isPost) {
  53. try {
  54. $post = $request->post();
  55. $res = Yii::$app->services->validate->validate($post, [
  56. [['id', 'user_id'], 'integer'],
  57. ]);
  58. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  59. $post['store_id'] = $this->store_id;
  60. $res = (new ClerkService(['mall_id' => $this->mall_id]))->addClerk($post);
  61. return $this->success('操作成功');
  62. } catch (\Exception $e) {
  63. return $this->error($e->getMessage());
  64. }
  65. }
  66. }
  67. }
  68. //删除核销员
  69. public function actionDelete()
  70. {
  71. $request = Yii::$app->request;
  72. if ($request->isAjax && $request->isPost) {
  73. try {
  74. $post = $request->post();
  75. $res = Yii::$app->services->validate->validate($post, [
  76. [['id'], 'integer']
  77. ]);
  78. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  79. $res = (new ClerkService(['mall_id' => $this->mall_id]))->deleteClerk($post);
  80. return $this->success('操作成功');
  81. } catch (\Exception $e) {
  82. return $this->error($e->getMessage());
  83. }
  84. }
  85. }
  86. //核销明细
  87. public function actionClerkLog()
  88. {
  89. $request = Yii::$app->request;
  90. if ($request->isAjax) {
  91. if ($request->isGet) {
  92. try {
  93. $get = $request->get();
  94. $res = Yii::$app->services->validate->validate($get, [
  95. [['page', 'limit'], 'integer'],
  96. [['clerk_id', 'user_id', 'order_no'], 'string'],
  97. ]);
  98. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  99. $list = (new ClerkService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->storeClerkLog($get);
  100. return $this->success('获取成功', $list);
  101. } catch (\Exception $e) {
  102. $this->error($e->getMessage());
  103. }
  104. }
  105. }
  106. return $this->render($this->action->id);
  107. }
  108. public function actionChangeClerkStatus()
  109. {
  110. $request = Yii::$app->request;
  111. if ($request->isAjax && $request->isPost) {
  112. try {
  113. $post = $request->post();
  114. $res = Yii::$app->services->validate->validate($post, [
  115. [['id', 'status'], 'integer'],
  116. ]);
  117. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  118. $res = (new ClerkService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->changeClerkStatus($post);
  119. return $this->success('操作成功');
  120. } catch (\Exception $e) {
  121. return $this->error($e->getMessage());
  122. }
  123. }
  124. }
  125. }