StaffStock.Class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 JinDouYun\Model\Department\MStaffStock;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\ResultWrapper;
  14. use Mall\Framework\Core\StatusCode;
  15. use JinDouYun\Cache\ShopCache;
  16. use JinDouYun\Controller\BaseController;
  17. use JinDouYun\Cache\TempSaveCache;
  18. class StaffStock extends BaseController
  19. {
  20. private $obj;
  21. private $objShopCache;
  22. private $objTempSaveCache;
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->obj = new MStaffStock($this->onlineEnterpriseId, $this->onlineUserId);
  27. $this->objShopCache = new ShopCache();
  28. $this->objTempSaveCache = new TempSaveCache();
  29. }
  30. /**
  31. * 添加和编辑商铺管理公共字段处理方法
  32. *
  33. * @return array
  34. */
  35. public function commonFieldFilter(){
  36. $params = $this->request->getRawJson();
  37. if( empty($params) ){
  38. $this->sendOutput('参数为空', ErrorCode::$paramError );
  39. }
  40. $shopData = [
  41. 'name' => isset($params['name']) ? $params['name'] : '',
  42. 'price' => isset($params['price']) ? $params['price'] : '',
  43. 'ot_price' => isset($params['ot_price']) ? $params['ot_price'] : '',
  44. 'image' => isset($params['image']) ? $params['image'] : '',
  45. ];
  46. //非暂存则验空
  47. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  48. foreach($shopData as $key => $value){
  49. if(empty($value) && $value !== 0){
  50. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  51. }
  52. }
  53. }
  54. $shopData['info']= isset($params['info']) ? $params['info'] : false;
  55. $shopData['introduce']= isset($params['introduce']) ? $params['introduce'] : false;
  56. $shopData['status']= isset($params['status']) ? $params['status'] : 1;
  57. return $shopData;
  58. }
  59. /**
  60. * 列表
  61. */
  62. public function list()
  63. {
  64. $params = $this->request->getRawJson();
  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['pm']) && !empty($params['pm'])){
  73. $selectParams['pm'] = $params['pm'];
  74. }
  75. if(isset($params['start_time']) && !empty($params['start_time'])){
  76. $selectParams['start_time'] = $params['start_time'];
  77. }
  78. if(isset($params['end_time']) && !empty($params['end_time'])){
  79. $selectParams['end_time'] = $params['end_time'];
  80. }
  81. $result = $this->obj->list($selectParams);
  82. if ($result->isSuccess()) {
  83. $returnData = $result->getData();
  84. $pageData = [
  85. 'pageIndex' => $params['page'],
  86. 'pageSize' => $params['pageSize'],
  87. 'pageTotal' => $returnData['total'],
  88. ];
  89. parent::sendOutput($returnData['data'], 0, $pageData);
  90. } else {
  91. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  92. }
  93. }
  94. /**
  95. * 添加
  96. * @throws \Exception
  97. */
  98. public function add()
  99. {
  100. $addStaffData = $this->commonFieldFilter();
  101. // $addStaffData['shop_id'] = $this->shopId;
  102. $addStaffData['enterprise_id'] = $this->onlineEnterpriseId;
  103. $result = $this->obj->insert($addStaffData);
  104. if ($result->isSuccess()) {
  105. parent::sendOutput($result->getData());
  106. } else {
  107. parent::sendOutput($result->getData(), $result->getErrorCode());
  108. }
  109. }
  110. /**
  111. * 详情
  112. * @return void
  113. */
  114. public function details()
  115. {
  116. $where = [];
  117. $id = $this->request->param('id');
  118. if(!empty($id)){
  119. $where['id'] = $id;
  120. }
  121. $result = $this->obj->details($where);
  122. if ($result->isSuccess()) {
  123. parent::sendOutput($result->getData());
  124. } else {
  125. parent::sendOutput($result->getData(), $result->getErrorCode());
  126. }
  127. }
  128. /**
  129. * 修改
  130. * @return void
  131. */
  132. public function update()
  133. {
  134. $id['id'] = $this->request->param('id');
  135. if (empty($id['id'])) {
  136. $this->sendOutput('参数为空', ErrorCode::$paramError);
  137. }
  138. $params = $this->commonFieldFilter();
  139. $result = $this->obj->update($params, $id);
  140. if ($result->isSuccess()) {
  141. parent::sendOutput($result->getData());
  142. } else {
  143. parent::sendOutput($result->getData(), $result->getErrorCode());
  144. }
  145. }
  146. public function delete()
  147. {
  148. $id['id'] = $this->request->param('id');
  149. if (empty($id['id'])) {
  150. $this->sendOutput('参数为空', ErrorCode::$paramError);
  151. }
  152. $result = $this->obj->delete($id);
  153. if ($result->isSuccess()) {
  154. parent::sendOutput($result->getData());
  155. } else {
  156. parent::sendOutput($result->getData(), $result->getErrorCode());
  157. }
  158. }
  159. }