Personnel.Class.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Controller\Enterprise;
  10. use JinDouYun\Model\Enterprise\MPersonnel;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Cache\ShopCache;
  15. use JinDouYun\Controller\BaseController;
  16. use JinDouYun\Cache\TempSaveCache;
  17. class Personnel extends BaseController
  18. {
  19. private $obj;
  20. private $objShopCache;
  21. private $objTempSaveCache;
  22. public function __construct($isCheckAcl = true, $isMustLogin = true)
  23. {
  24. parent::__construct($isCheckAcl, $isMustLogin);
  25. $this->obj = new MPersonnel($this->onlineEnterpriseId, $this->onlineUserId);
  26. $this->objShopCache = new ShopCache();
  27. $this->objTempSaveCache = new TempSaveCache();
  28. }
  29. /**
  30. * 添加和编辑商铺管理公共字段处理方法
  31. *
  32. * @return array
  33. */
  34. public function commonFieldFilter(){
  35. $params = $this->request->getRawJson();
  36. if( empty($params) ){
  37. $this->sendOutput('参数为空', ErrorCode::$paramError );
  38. }
  39. $shopData = [
  40. 'name' => isset($params['name']) ? $params['name'] : '',
  41. 'duties' => isset($params['duties']) ? $params['duties'] : '',
  42. 'type' => isset($params['type']) ? $params['type'] : '',
  43. 'avatar' => isset($params['avatar']) ? $params['avatar'] : '',
  44. ];
  45. //非暂存则验空
  46. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  47. foreach($shopData as $key => $value){
  48. if(empty($value) && $value !== 0){
  49. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  50. }
  51. }
  52. }
  53. $shopData['phone']= isset($params['phone']) ? $params['phone'] : false;
  54. $shopData['address']= isset($params['address']) ? $params['address'] : false;
  55. $shopData['job_no']= isset($params['job_no']) ? $params['job_no'] : false;
  56. $shopData['business']= isset($params['business']) ? $params['business'] : false;
  57. return $shopData;
  58. }
  59. /**
  60. * 列表
  61. */
  62. public function list()
  63. {
  64. $params = $this->request->params();
  65. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  66. $selectParams['limit'] = $pageParams['limit'];
  67. $selectParams['offset'] = $pageParams['offset'];
  68. //uid
  69. if(isset($params['name']) && !empty($params['name'])){
  70. $selectParams['name'] = $params['name'];
  71. }
  72. if(isset($params['type']) && !empty($params['type'])){
  73. $selectParams['type'] = $params['type'];
  74. }
  75. $selectParams['en_id'] = $this->onlineEnterpriseId;
  76. $result = $this->obj->list($selectParams);
  77. if ($result->isSuccess()) {
  78. $returnData = $result->getData();
  79. $pageData = [
  80. 'pageIndex' => $params['page'],
  81. 'pageSize' => $params['pageSize'],
  82. 'pageTotal' => $returnData['total'],
  83. ];
  84. parent::sendOutput($returnData['data'], 0, $pageData);
  85. } else {
  86. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  87. }
  88. }
  89. /**
  90. * 添加
  91. * @throws \Exception
  92. */
  93. public function add()
  94. {
  95. $addStaffData = $this->commonFieldFilter();
  96. // $addStaffData['shop_id'] = $this->shopId;
  97. $addStaffData['en_id'] = $this->onlineEnterpriseId;
  98. $result = $this->obj->insert($addStaffData);
  99. if ($result->isSuccess()) {
  100. parent::sendOutput($result->getData());
  101. } else {
  102. parent::sendOutput($result->getData(), $result->getErrorCode());
  103. }
  104. }
  105. /**
  106. * 详情
  107. * @return void
  108. */
  109. public function details()
  110. {
  111. $where = [];
  112. $id = $this->request->param('id');
  113. if(!empty($id)){
  114. $where['id'] = $id;
  115. }
  116. $result = $this->obj->details($where);
  117. if ($result->isSuccess()) {
  118. parent::sendOutput($result->getData());
  119. } else {
  120. parent::sendOutput($result->getData(), $result->getErrorCode());
  121. }
  122. }
  123. /**
  124. * 修改
  125. * @return void
  126. */
  127. public function update()
  128. {
  129. $id['id'] = $this->request->param('id');
  130. if (empty($id['id'])) {
  131. $this->sendOutput('参数为空', ErrorCode::$paramError);
  132. }
  133. $params = $this->commonFieldFilter();
  134. $result = $this->obj->update($params, $id);
  135. if ($result->isSuccess()) {
  136. parent::sendOutput($result->getData());
  137. } else {
  138. parent::sendOutput($result->getData(), $result->getErrorCode());
  139. }
  140. }
  141. public function delete()
  142. {
  143. $id['id'] = $this->request->param('id');
  144. if (empty($id['id'])) {
  145. $this->sendOutput('参数为空', ErrorCode::$paramError);
  146. }
  147. $result = $this->obj->delete($id);
  148. if ($result->isSuccess()) {
  149. parent::sendOutput($result->getData());
  150. } else {
  151. parent::sendOutput($result->getData(), $result->getErrorCode());
  152. }
  153. }
  154. }