Setting.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qisse
  5. * Date: 2017/6/27
  6. * Time: 20:02
  7. */
  8. namespace app\master\logic;
  9. use app\core\model\Banner;
  10. use app\core\model\Channel;
  11. use tool\Common;
  12. class Setting extends Base
  13. {
  14. /**
  15. * @api {post} setting/bannerUpdate 新增/更新banner统一接口
  16. * @apiVersion 1.0.0
  17. * @apiName update
  18. * @apiDescription 新增/更新banner统一接口
  19. * @apiGroup Setting
  20. *
  21. * @apiParam {Number} bannerID 类型ID,更新时为必传字段,新增时保持bannerID必须为0
  22. * @apiParam {Number} {clientType=1,2} 客户端类型,1为app,2为pc
  23. * @apiParam {Number} {status=1,2} 状态,1为上线,2为下线
  24. * @apiParam {String} thumb 图片url
  25. * @apiParam {String} title 标题
  26. * @apiParam {String} link 点击图片之后跳转
  27. * @apiParamExample {json} 发送报文:
  28. {
  29. "bannerID": 2,
  30. "clientType": 1,
  31. "status": 2,
  32. "thumb": "http://www.baidu.com/image.jpg",
  33. "link": "http://www.baidu.com/"
  34. }
  35. *
  36. * @apiSuccess {Number} bannerID bannerID
  37. * @apiSuccessExample {json} 返回json数据(举例):
  38. {
  39. "code": 1,
  40. "msg": "操作成功",
  41. "content": {
  42. "bannerID": 12
  43. }
  44. }
  45. * @apiUse CreateUserError
  46. */
  47. public function bannerUpdate()
  48. {
  49. if(!isset($this->app['bannerID']) ||!$this->app['bannerID']) {
  50. $model = Banner::create([
  51. 'title' => $this->app['title'],
  52. 'clientType' => $this->app['clientType'],
  53. 'status'=> 2,
  54. 'thumb' => $this->app['thumb'],
  55. 'link' => $this->app['link']
  56. ]);
  57. }
  58. else {
  59. $model = Banner::update([
  60. 'title' => $this->app['title'],
  61. 'clientType' => $this->app['clientType'],
  62. 'status'=> 2,
  63. 'thumb' => $this->app['thumb'],
  64. 'link' => $this->app['link']
  65. ], [
  66. 'bannerID'=>$this->app['bannerID']
  67. ]);
  68. $model['bannerID'] = $this->app['bannerID'];
  69. }
  70. return Common::rm(1, '操作成功', [
  71. 'bannerID'=>$model['bannerID']
  72. ]);
  73. }
  74. public function getBannerList() {
  75. $map = [];
  76. if(isset($this->app['clientType']) && $this->app['clientType']) {
  77. $map['clientType'] = $this->app['clientType'];
  78. }
  79. if(isset($this->app['clientType']) && $this->app['status']) {
  80. $map['status'] = $this->app['status'];
  81. }
  82. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  83. $this->app['pageIndex'] = 1;
  84. }
  85. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  86. $this->app['pageItemCount'] = 10;
  87. }
  88. $count = Banner::where($map)->count();
  89. $list = Banner::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  90. if($list->isEmpty()) {
  91. return Common::rm(-2, '数据为空');
  92. }
  93. $list->append(['statusText','clientTypeText']);
  94. return Common::rm(1, '操作成功', [
  95. 'bannerList'=>$list,
  96. 'count'=>$count,
  97. 'pageItemCount'=>$this->app['pageItemCount'],
  98. ]);
  99. }
  100. public function bannerGetDetail() {
  101. $item = Banner::get($this->app['bannerID']);
  102. if(!$item) {
  103. return Common::rm(-32, '没有数据');
  104. }
  105. return Common::rm(1, '操作成功', [
  106. 'detail'=>$item
  107. ]);
  108. }
  109. /**
  110. * @api {post} setting/bannerActionOnline banner上线
  111. * @apiVersion 1.0.0
  112. * @apiName bannerActionOnline
  113. * @apiDescription banner上线
  114. * @apiGroup Setting
  115. *
  116. * @apiParam {Number} bannerID bannerID
  117. * @apiParamExample {json} 发送报文:
  118. {
  119. "bannerID": 12
  120. }
  121. *
  122. * @apiSuccess {Object} detail banner部分
  123. * @apiSuccess {Number} detail.status 更新bannerID
  124. * @apiSuccess {String} detail.statusText 更新bannerID
  125. * @apiSuccessExample {json} 返回json数据(举例):
  126. {
  127. "code": 1,
  128. "msg": "操作成功",
  129. "content": {
  130. detail:{
  131. "status": 1,
  132. "statusText": "上线"
  133. }
  134. }
  135. }
  136. * @apiUse CreateUserError
  137. */
  138. public function bannerActionOnline() {
  139. $item = Banner::get($this->app['bannerID']);
  140. if(!$item) {
  141. return Common::rm(-2, '没有数据');
  142. }
  143. $item['status'] = Banner::STATUS_ONLINE;
  144. $item->save();
  145. return Common::rm(1, '操作成功', [
  146. 'detail'=>$item->append(['statusText'])->visible(['status'])
  147. ]);
  148. }
  149. /**
  150. * @api {post} setting/bannerActionOffline banner下线
  151. * @apiVersion 1.0.0
  152. * @apiName bannerActionOffline
  153. * @apiDescription banner下线
  154. * @apiGroup Setting
  155. *
  156. * @apiParam {Number} bannerID bannerID
  157. * @apiParamExample {json} 发送报文:
  158. {
  159. "bannerID": 12
  160. }
  161. *
  162. * @apiSuccess {Object} detail banner部分
  163. * @apiSuccess {Number} detail.status 更新bannerID
  164. * @apiSuccess {String} detail.statusText 更新bannerID
  165. * @apiSuccessExample {json} 返回json数据(举例):
  166. {
  167. "code": 1,
  168. "msg": "操作成功",
  169. "content": {
  170. detail:{
  171. "status": 2,
  172. "statusText": "下线"
  173. }
  174. }
  175. }
  176. * @apiUse CreateUserError
  177. */
  178. public function bannerActionOffline() {
  179. $item = Banner::get($this->app['bannerID']);
  180. if(!$item) {
  181. return Common::rm(-2, '没有数据');
  182. }
  183. $item['status'] = Banner::STATUS_OFFLINE;
  184. $item->save();
  185. return Common::rm(1, '操作成功', [
  186. 'detail'=>$item->append(['statusText'])->visible(['status'])
  187. ]);
  188. }
  189. /**
  190. * @api {post} setting/bannerActionDelete 删除banner条目
  191. * @apiVersion 1.0.0
  192. * @apiName bannerActionDelete
  193. * @apiDescription 删除banner条目
  194. * @apiGroup Subject
  195. *
  196. * @apiParam {Number} bannerID bannerID
  197. * @apiParamExample {json} 发送报文:
  198. {
  199. "bannerID": 12
  200. }
  201. *
  202. * @apiSuccessExample {json} 返回json数据(举例):
  203. {
  204. "code": 1,
  205. "msg": "操作成功"
  206. }
  207. * @apiUse CreateUserError
  208. */
  209. public function bannerActionDelete() {
  210. $model = Model::get($this->app['bannerID']);
  211. $model->delete();
  212. return Common::rm(1, '操作成功');
  213. }
  214. public function channelGetDetail() {
  215. $item = Channel::get($this->app['channelID']);
  216. if(!$item) {
  217. return Common::rm(-32, '没有数据');
  218. }
  219. return Common::rm(1, '操作成功', [
  220. 'detail'=>$item
  221. ]);
  222. }
  223. public function channelUpdate() {
  224. if(!isset($this->app['channelID']) ||!$this->app['channelID']) {
  225. $model = Channel::create([
  226. 'name' => $this->app['name'],
  227. 'code' => $this->app['code'],
  228. 'url'=>$this->app['url'],
  229. 'status'=>1
  230. ]);
  231. }
  232. else {
  233. $model = Channel::update([
  234. 'name' => $this->app['name'],
  235. 'code' => $this->app['code'],
  236. 'url'=>$this->app['url']
  237. ], [
  238. 'channelID'=>$this->app['channelID']
  239. ]);
  240. $model['channelID'] = $this->app['channelID'];
  241. }
  242. return Common::rm(1, '操作成功', [
  243. 'channelID'=>$model['channelID']
  244. ]);
  245. }
  246. public function channelGetList() {
  247. $map = [];
  248. if(isset($this->app['clientType']) && $this->app['clientType']) {
  249. $map['clientType'] = $this->app['clientType'];
  250. }
  251. if(isset($this->app['clientType']) && $this->app['status']) {
  252. $map['status'] = $this->app['status'];
  253. }
  254. if(isset($this->app['keyword']) && $this->app['keyword']) {
  255. $map['name|code'] = ['like', '%'.$this->app['keyword'].'%'];
  256. }
  257. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  258. $this->app['pageIndex'] = 1;
  259. }
  260. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  261. $this->app['pageItemCount'] = 10;
  262. }
  263. $count = Channel::where($map)->count();
  264. $list = Channel::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  265. if($list->isEmpty()) {
  266. return Common::rm(-2, '数据为空');
  267. }
  268. return Common::rm(1, '操作成功', [
  269. 'channelList'=>$list,
  270. 'count'=>$count,
  271. 'pageItemCount'=>$this->app['pageItemCount'],
  272. ]);
  273. }
  274. }