HoldersRecord.Class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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\Holders;
  10. use JinDouYun\Model\Holders\MHoldersRecord;
  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 HoldersRecord 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 MHoldersRecord($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. 'price' => isset($params['price']) ? $params['price'] : '',
  42. 'ot_price' => isset($params['ot_price']) ? $params['ot_price'] : '',
  43. 'image' => isset($params['image']) ? $params['image'] : '',
  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['info']= isset($params['info']) ? $params['info'] : false;
  54. $shopData['introduce']= isset($params['introduce']) ? $params['introduce'] : false;
  55. $shopData['status']= isset($params['status']) ? $params['status'] : 1;
  56. return $shopData;
  57. }
  58. /**
  59. * 列表
  60. */
  61. public function list()
  62. {
  63. $params = $this->request->getRawJson();
  64. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  65. $selectParams['limit'] = $pageParams['limit'];
  66. $selectParams['offset'] = $pageParams['offset'];
  67. //uid
  68. if(isset($params['name']) && !empty($params['name'])){
  69. $selectParams['name'] = $params['name'];
  70. }
  71. if(isset($params['pm']) && !empty($params['pm'])){
  72. $selectParams['pm'] = $params['pm'];
  73. }
  74. if(isset($params['start_time']) && !empty($params['start_time'])){
  75. $selectParams['start_time'] = $params['start_time'];
  76. }
  77. if(isset($params['end_time']) && !empty($params['end_time'])){
  78. $selectParams['end_time'] = $params['end_time'];
  79. }
  80. if(isset($params['type']) && !empty($params['type'])){
  81. $selectParams['type'] = $params['type'];
  82. }
  83. $result = $this->obj->list($selectParams);
  84. if ($result->isSuccess()) {
  85. $returnData = $result->getData();
  86. $pageData = [
  87. 'pageIndex' => $params['page'],
  88. 'pageSize' => $params['pageSize'],
  89. 'pageTotal' => $returnData['total'],
  90. ];
  91. parent::sendOutput($returnData['data'], 0, $pageData);
  92. } else {
  93. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  94. }
  95. }
  96. /**
  97. * 添加
  98. * @throws \Exception
  99. */
  100. public function add()
  101. {
  102. $addStaffData = $this->commonFieldFilter();
  103. // $addStaffData['shop_id'] = $this->shopId;
  104. $addStaffData['enterprise_id'] = $this->onlineEnterpriseId;
  105. $result = $this->obj->insert($addStaffData);
  106. if ($result->isSuccess()) {
  107. parent::sendOutput($result->getData());
  108. } else {
  109. parent::sendOutput($result->getData(), $result->getErrorCode());
  110. }
  111. }
  112. /**
  113. * 详情
  114. * @return void
  115. */
  116. public function details()
  117. {
  118. $where = [];
  119. $id = $this->request->param('id');
  120. if(!empty($id)){
  121. $where['id'] = $id;
  122. }
  123. $result = $this->obj->details($where);
  124. if ($result->isSuccess()) {
  125. parent::sendOutput($result->getData());
  126. } else {
  127. parent::sendOutput($result->getData(), $result->getErrorCode());
  128. }
  129. }
  130. /**
  131. * 修改
  132. * @return void
  133. */
  134. public function update()
  135. {
  136. $id['id'] = $this->request->param('id');
  137. if (empty($id['id'])) {
  138. $this->sendOutput('参数为空', ErrorCode::$paramError);
  139. }
  140. $params = $this->commonFieldFilter();
  141. $result = $this->obj->update($params, $id);
  142. if ($result->isSuccess()) {
  143. parent::sendOutput($result->getData());
  144. } else {
  145. parent::sendOutput($result->getData(), $result->getErrorCode());
  146. }
  147. }
  148. public function delete()
  149. {
  150. $id['id'] = $this->request->param('id');
  151. if (empty($id['id'])) {
  152. $this->sendOutput('参数为空', ErrorCode::$paramError);
  153. }
  154. $result = $this->obj->delete($id);
  155. if ($result->isSuccess()) {
  156. parent::sendOutput($result->getData());
  157. } else {
  158. parent::sendOutput($result->getData(), $result->getErrorCode());
  159. }
  160. }
  161. }