ShopProject.Class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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\Shop;
  10. use JinDouYun\Model\Enterprise\MEnterprise;
  11. use JinDouYun\Model\Shop\MShopProject;
  12. use JinDouYun\Model\Shop\MShopSubscribe;
  13. use Mall\Framework\Core\ErrorCode;
  14. use Mall\Framework\Core\ResultWrapper;
  15. use Mall\Framework\Core\StatusCode;
  16. use JinDouYun\Cache\ShopCache;
  17. use JinDouYun\Controller\BaseController;
  18. use JinDouYun\Model\Shop\MShop;
  19. use JinDouYun\Cache\TempSaveCache;
  20. class ShopProject extends BaseController
  21. {
  22. private $objMShopProject;
  23. private $objShopCache;
  24. private $objTempSaveCache;
  25. private $objSub;
  26. public function __construct($isCheckAcl = true, $isMustLogin = true)
  27. {
  28. parent::__construct($isCheckAcl, $isMustLogin);
  29. $this->objMShopProject = new MShopProject($this->onlineEnterpriseId, $this->onlineUserId);
  30. $this->objShopCache = new ShopCache();
  31. $this->objTempSaveCache = new TempSaveCache();
  32. $this->objSub = new MShopSubscribe($this->onlineEnterpriseId, $this->onlineUserId);
  33. }
  34. /**
  35. * 添加和编辑商铺管理公共字段处理方法
  36. *
  37. * @return array
  38. */
  39. public function commonFieldFilter(){
  40. $params = $this->request->getRawJson();
  41. if( empty($params) ){
  42. $this->sendOutput('参数为空', ErrorCode::$paramError );
  43. }
  44. $Data = [
  45. 'name' => isset($params['name']) ? $params['name'] : '',
  46. 'image' => isset($params['image']) ? $params['image'] : '',
  47. 'slider_image' => isset($params['slider_image']) ? $params['slider_image'] : '',
  48. 'price' => isset($params['price']) ? $params['price'] : '',
  49. 'ot_price' => isset($params['ot_price']) ? $params['ot_price'] : '',
  50. 'cost_price' => isset($params['cost_price']) ? $params['cost_price'] : '',
  51. 'service_time' => isset($params['service_time']) ? $params['service_time'] : '',
  52. 'commission' => isset($params['commission']) ? $params['commission'] : '',
  53. ];
  54. //非暂存则验空
  55. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  56. foreach($Data as $key => $value){
  57. if(empty($value) && $value !== 0){
  58. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  59. }
  60. }
  61. }
  62. $Data['result']= isset($params['result']) ? $params['result'] : false;
  63. $Data['info']= isset($params['info']) ? $params['info'] : false;
  64. $Data['shop_id']= isset($params['shop_id']) ? $params['shop_id'] : false;
  65. return $Data;
  66. }
  67. /**
  68. * 列表
  69. */
  70. public function list()
  71. {
  72. $params = $this->request->params();
  73. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  74. $selectParams['limit'] = $pageParams['limit'];
  75. $selectParams['offset'] = $pageParams['offset'];
  76. $selectParams['enterprise_id'] = $this->onlineEnterpriseId;
  77. // if ($this->shopId){
  78. // $selectParams['shop_id'] = $this->shopId;
  79. // }
  80. //项目昵称
  81. if(isset($params['name']) && !empty($params['name'])){
  82. $selectParams['name'] = $params['name'];
  83. }
  84. if(isset($params['is_show']) && !empty($params['is_show'])){
  85. $selectParams['is_show'] = $params['is_show'] == 1? 0 : 1;
  86. }
  87. $result = $this->objMShopProject->list($selectParams);
  88. if ($result->isSuccess()) {
  89. $returnData = $result->getData();
  90. foreach ($returnData['data'] as &$item)
  91. {
  92. $item['sold'] = $this->objSub->count([['project', 'like', '%'.$item['id'].'%']]);
  93. }
  94. $pageData = [
  95. 'pageIndex' => $params['page'],
  96. 'pageSize' => $params['pageSize'],
  97. 'pageTotal' => $returnData['total'],
  98. ];
  99. parent::sendOutput($returnData['data'], 0, $pageData);
  100. } else {
  101. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  102. }
  103. }
  104. /**
  105. * 添加项目
  106. * @throws \Exception
  107. */
  108. public function add()
  109. {
  110. $addStaffData = $this->commonFieldFilter();
  111. $addStaffData['enterprise_id'] = $this->onlineEnterpriseId;
  112. // if ($this->shopId){
  113. // $addStaffData['shop_id'] = $this->shopId;
  114. // }
  115. $result = $this->objMShopProject->insert($addStaffData);
  116. if ($result->isSuccess()) {
  117. parent::sendOutput($result->getData());
  118. } else {
  119. parent::sendOutput($result->getData(), $result->getErrorCode());
  120. }
  121. }
  122. /**
  123. * 详情
  124. * @return void
  125. */
  126. public function details()
  127. {
  128. $where = [];
  129. $id = $this->request->param('id');
  130. if(!empty($id)){
  131. $where['id'] = $id;
  132. }
  133. $result = $this->objMShopProject->details($where);
  134. if ($result->isSuccess()) {
  135. $result = $result->getData();
  136. $result['sold'] = $this->objSub->count([['project', 'like', '%'.$result['id'].'%']]);
  137. $result['result'] = html_entity_decode($result['result']);
  138. parent::sendOutput($result);
  139. } else {
  140. parent::sendOutput($result->getData(), $result->getErrorCode());
  141. }
  142. }
  143. /**
  144. * 修改
  145. * @return void
  146. */
  147. public function update()
  148. {
  149. $id['id'] = $this->request->param('id');
  150. if (empty($id['id'])) {
  151. $this->sendOutput('参数为空', ErrorCode::$paramError);
  152. }
  153. $params = $this->commonFieldFilter();
  154. $result = $this->objMShopProject->update($params, $id);
  155. if ($result->isSuccess()) {
  156. parent::sendOutput($result->getData());
  157. } else {
  158. parent::sendOutput($result->getData(), $result->getErrorCode());
  159. }
  160. }
  161. public function delete()
  162. {
  163. $id['id'] = $this->request->param('id');
  164. if (empty($id['id'])) {
  165. $this->sendOutput('参数为空', ErrorCode::$paramError);
  166. }
  167. $result = $this->objMShopProject->delete($id);
  168. if ($result->isSuccess()) {
  169. parent::sendOutput($result->getData());
  170. } else {
  171. parent::sendOutput($result->getData(), $result->getErrorCode());
  172. }
  173. }
  174. /**
  175. * @return void
  176. */
  177. public function set_shop()
  178. {
  179. $id['id'] = $this->request->param('id');
  180. $data['is_show'] = $this->request->param('is_show');
  181. if (empty($id['id'])) {
  182. $this->sendOutput('参数为空', ErrorCode::$paramError);
  183. }
  184. $result = $this->objMShopProject->update($data, $id);
  185. if ($result->isSuccess()) {
  186. parent::sendOutput($result->getData());
  187. } else {
  188. parent::sendOutput($result->getData(), $result->getErrorCode());
  189. }
  190. }
  191. }