StaffLadder.Class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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\Department;
  10. use JinDouYun\Model\Department\MStaffLadder;
  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 StaffLadder 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 MStaffLadder($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. 'number' => isset($params['number']) ? $params['number'] : '',
  42. 'stock' => isset($params['stock']) ? $params['stock'] : '',
  43. ];
  44. //非暂存则验空
  45. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  46. foreach($shopData as $key => $value){
  47. if(empty($value) && $value !== 0){
  48. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  49. }
  50. }
  51. }
  52. return $shopData;
  53. }
  54. /**
  55. * 列表
  56. */
  57. public function list()
  58. {
  59. $params = $this->request->getRawJson();
  60. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  61. $selectParams['limit'] = $pageParams['limit'];
  62. $selectParams['offset'] = $pageParams['offset'];
  63. //uid
  64. if(isset($params['name']) && !empty($params['name'])){
  65. $selectParams['name'] = $params['name'];
  66. }
  67. $result = $this->obj->list($selectParams);
  68. if ($result->isSuccess()) {
  69. $returnData = $result->getData();
  70. $pageData = [
  71. 'pageIndex' => $params['page'],
  72. 'pageSize' => $params['pageSize'],
  73. 'pageTotal' => $returnData['total'],
  74. ];
  75. parent::sendOutput($returnData['data'], 0, $pageData);
  76. } else {
  77. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  78. }
  79. }
  80. /**
  81. * 添加
  82. * @throws \Exception
  83. */
  84. public function add()
  85. {
  86. $addStaffData = $this->commonFieldFilter();
  87. // $addStaffData['shop_id'] = $this->shopId;
  88. $addStaffData['enterpriseId'] = $this->onlineEnterpriseId;
  89. $result = $this->obj->insert($addStaffData);
  90. if ($result->isSuccess()) {
  91. parent::sendOutput($result->getData());
  92. } else {
  93. parent::sendOutput($result->getData(), $result->getErrorCode());
  94. }
  95. }
  96. /**
  97. * 详情
  98. * @return void
  99. */
  100. public function details()
  101. {
  102. $where = [];
  103. $id = $this->request->param('id');
  104. if(!empty($id)){
  105. $where['id'] = $id;
  106. }
  107. $result = $this->obj->details($where);
  108. if ($result->isSuccess()) {
  109. parent::sendOutput($result->getData());
  110. } else {
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. }
  114. /**
  115. * 修改
  116. * @return void
  117. */
  118. public function update()
  119. {
  120. $id['id'] = $this->request->param('id');
  121. if (empty($id['id'])) {
  122. $this->sendOutput('参数为空', ErrorCode::$paramError);
  123. }
  124. $params = $this->commonFieldFilter();
  125. $result = $this->obj->update($params, $id);
  126. if ($result->isSuccess()) {
  127. parent::sendOutput($result->getData());
  128. } else {
  129. parent::sendOutput($result->getData(), $result->getErrorCode());
  130. }
  131. }
  132. public function delete()
  133. {
  134. $id['id'] = $this->request->param('id');
  135. if (empty($id['id'])) {
  136. $this->sendOutput('参数为空', ErrorCode::$paramError);
  137. }
  138. $result = $this->obj->delete($id);
  139. if ($result->isSuccess()) {
  140. parent::sendOutput($result->getData());
  141. } else {
  142. parent::sendOutput($result->getData(), $result->getErrorCode());
  143. }
  144. }
  145. }