Active.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 tool\Common;
  11. class Active extends Base
  12. {
  13. /**
  14. * @api {post} setting/bannerUpdate 新增/更新banner统一接口
  15. * @apiVersion 1.0.0
  16. * @apiName update
  17. * @apiDescription 新增/更新banner统一接口
  18. * @apiGroup Setting
  19. *
  20. * @apiParam {Number} bannerID 类型ID,更新时为必传字段,新增时保持bannerID必须为0
  21. * @apiParam {Number} {clientType=1,2} 客户端类型,1为app,2为pc
  22. * @apiParam {Number} {status=1,2} 状态,1为上线,2为下线
  23. * @apiParam {String} thumb 图片url
  24. * @apiParam {String} title 标题
  25. * @apiParam {String} link 点击图片之后跳转
  26. * @apiParamExample {json} 发送报文:
  27. {
  28. "bannerID": 2,
  29. "clientType": 1,
  30. "status": 2,
  31. "thumb": "http://www.baidu.com/image.jpg",
  32. "link": "http://www.baidu.com/"
  33. }
  34. *
  35. * @apiSuccess {Number} bannerID bannerID
  36. * @apiSuccessExample {json} 返回json数据(举例):
  37. {
  38. "code": 1,
  39. "msg": "操作成功",
  40. "content": {
  41. "bannerID": 12
  42. }
  43. }
  44. * @apiUse CreateUserError
  45. */
  46. public function bannerUpdate()
  47. {
  48. if(!isset($this->app['bannerID']) ||!$this->app['bannerID']) {
  49. $model = Banner::create([
  50. 'title' => $this->app['title'],
  51. 'clientType' => $this->app['clientType'],
  52. 'status'=> 2,
  53. 'thumb' => $this->app['thumb'],
  54. 'link' => $this->app['link']
  55. ]);
  56. }
  57. else {
  58. $model = Banner::update([
  59. 'title' => $this->app['title'],
  60. 'clientType' => $this->app['clientType'],
  61. 'status'=> 2,
  62. 'thumb' => $this->app['thumb'],
  63. 'link' => $this->app['link']
  64. ], [
  65. 'bannerID'=>$this->app['bannerID']
  66. ]);
  67. $model['bannerID'] = $this->app['bannerID'];
  68. }
  69. return Common::rm(1, '操作成功', [
  70. 'bannerID'=>$model['bannerID']
  71. ]);
  72. }
  73. public function getBannerList() {
  74. $map = [];
  75. if(isset($this->app['clientType']) && $this->app['clientType']) {
  76. $map['clientType'] = $this->app['clientType'];
  77. }
  78. if(isset($this->app['clientType']) && $this->app['status']) {
  79. $map['status'] = $this->app['status'];
  80. }
  81. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  82. $this->app['pageIndex'] = 1;
  83. }
  84. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  85. $this->app['pageItemCount'] = 10;
  86. }
  87. $count = Banner::where($map)->count();
  88. $list = Banner::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  89. if($list->isEmpty()) {
  90. return Common::rm(-2, '数据为空');
  91. }
  92. $list->append(['statusText','clientTypeText']);
  93. return Common::rm(1, '操作成功', [
  94. 'bannerList'=>$list,
  95. 'count'=>$count,
  96. 'pageItemCount'=>$this->app['pageItemCount'],
  97. ]);
  98. }
  99. public function bannerGetDetail() {
  100. $item = Banner::get($this->app['bannerID']);
  101. if(!$item) {
  102. return Common::rm(-32, '没有数据');
  103. }
  104. return Common::rm(1, '操作成功', [
  105. 'detail'=>$item
  106. ]);
  107. }
  108. /**
  109. * @api {post} setting/bannerActionOnline banner上线
  110. * @apiVersion 1.0.0
  111. * @apiName bannerActionOnline
  112. * @apiDescription banner上线
  113. * @apiGroup Setting
  114. *
  115. * @apiParam {Number} bannerID bannerID
  116. * @apiParamExample {json} 发送报文:
  117. {
  118. "bannerID": 12
  119. }
  120. *
  121. * @apiSuccess {Object} detail banner部分
  122. * @apiSuccess {Number} detail.status 更新bannerID
  123. * @apiSuccess {String} detail.statusText 更新bannerID
  124. * @apiSuccessExample {json} 返回json数据(举例):
  125. {
  126. "code": 1,
  127. "msg": "操作成功",
  128. "content": {
  129. detail:{
  130. "status": 1,
  131. "statusText": "上线"
  132. }
  133. }
  134. }
  135. * @apiUse CreateUserError
  136. */
  137. public function bannerActionOnline() {
  138. $item = Banner::get($this->app['bannerID']);
  139. if(!$item) {
  140. return Common::rm(-2, '没有数据');
  141. }
  142. $item['status'] = Banner::STATUS_ONLINE;
  143. $item->save();
  144. return Common::rm(1, '操作成功', [
  145. 'detail'=>$item->append(['statusText'])->visible(['status'])
  146. ]);
  147. }
  148. /**
  149. * @api {post} setting/bannerActionOffline banner下线
  150. * @apiVersion 1.0.0
  151. * @apiName bannerActionOffline
  152. * @apiDescription banner下线
  153. * @apiGroup Setting
  154. *
  155. * @apiParam {Number} bannerID bannerID
  156. * @apiParamExample {json} 发送报文:
  157. {
  158. "bannerID": 12
  159. }
  160. *
  161. * @apiSuccess {Object} detail banner部分
  162. * @apiSuccess {Number} detail.status 更新bannerID
  163. * @apiSuccess {String} detail.statusText 更新bannerID
  164. * @apiSuccessExample {json} 返回json数据(举例):
  165. {
  166. "code": 1,
  167. "msg": "操作成功",
  168. "content": {
  169. detail:{
  170. "status": 2,
  171. "statusText": "下线"
  172. }
  173. }
  174. }
  175. * @apiUse CreateUserError
  176. */
  177. public function bannerActionOffline() {
  178. $item = Banner::get($this->app['bannerID']);
  179. if(!$item) {
  180. return Common::rm(-2, '没有数据');
  181. }
  182. $item['status'] = Banner::STATUS_OFFLINE;
  183. $item->save();
  184. return Common::rm(1, '操作成功', [
  185. 'detail'=>$item->append(['statusText'])->visible(['status'])
  186. ]);
  187. }
  188. /**
  189. * @api {post} setting/bannerActionDelete 删除banner条目
  190. * @apiVersion 1.0.0
  191. * @apiName bannerActionDelete
  192. * @apiDescription 删除banner条目
  193. * @apiGroup Subject
  194. *
  195. * @apiParam {Number} bannerID bannerID
  196. * @apiParamExample {json} 发送报文:
  197. {
  198. "bannerID": 12
  199. }
  200. *
  201. * @apiSuccessExample {json} 返回json数据(举例):
  202. {
  203. "code": 1,
  204. "msg": "操作成功"
  205. }
  206. * @apiUse CreateUserError
  207. */
  208. public function bannerActionDelete() {
  209. $model = Model::get($this->app['bannerID']);
  210. $model->delete();
  211. return Common::rm(1, '操作成功');
  212. }
  213. }