Market.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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\Active;
  10. use app\core\model\Hongbao;
  11. use app\core\model\HongbaoPlan;
  12. use app\core\model\Sms;
  13. use app\core\model\User;
  14. use tool\Common;
  15. class Market extends Base
  16. {
  17. /**
  18. * @api {post} market/activeUpdate 新增/更新active统一接口
  19. * @apiVersion 1.0.0
  20. * @apiName activeUpdate
  21. * @apiDescription 新增/更新active统一接口
  22. * @apiGroup Setting
  23. *
  24. * @apiParam {Number} activeID 类型ID,更新时为必传字段,新增时保持bannerID必须为0
  25. * @apiParam {String} thumbPc pc图片url
  26. * @apiParam {String} thumbApp app图片Url
  27. * @apiParam {String} linkPc 图片url
  28. * @apiParam {String} linkApp 图片url
  29. * @apiParam {String} title 标题
  30. * @apiParam {String} note 备注
  31. * @apiParam {String} {isOnLinePc=0,1} pc是否在线上,0-线下,1线上
  32. * @apiParam {String} {isOnLineApp=0,1} app是否在线上,0-线下,1线上
  33. * @apiParamExample {json} 发送报文:
  34. {
  35. "activeID": 2,
  36. "thumbPc": "http://www.baidu.com/image.jpg",
  37. "thumbApp": "http://www.baidu.com/",
  38. "linkPc": "http://www.baidu.com/image.jpg",
  39. "linkApp": "http://www.baidu.com/",
  40. "title": "春旗佳节游泳包",
  41. "note": "春旗佳节游泳包撒的发生的发生大法师打发斯蒂芬",
  42. "isOnLinePc": 0,
  43. "isOnLineApp": 1
  44. }
  45. *
  46. * @apiSuccess {Number} bannerID bannerID
  47. * @apiSuccessExample {json} 返回json数据(举例):
  48. {
  49. "code": 1,
  50. "msg": "操作成功",
  51. "content": {
  52. "activeID": 12
  53. }
  54. }
  55. * @apiUse CreateUserError
  56. */
  57. public function activeUpdate()
  58. {
  59. if(!isset($this->app['activeID']) ||!$this->app['activeID']) {
  60. $model = Active::create([
  61. 'title' => $this->app['title'],
  62. 'note' => $this->app['note'],
  63. 'thumbPc' => $this->app['thumbPc'],
  64. 'thumbApp' => $this->app['thumbApp'],
  65. 'linkPc'=> $this->app['linkPc'],
  66. 'linkApp' => $this->app['linkApp'],
  67. 'listOrder' => 1
  68. ]);
  69. }
  70. else {
  71. $model = Active::update([
  72. 'title' => $this->app['title'],
  73. 'note' => $this->app['note'],
  74. 'thumbPc' => $this->app['thumbPc'],
  75. 'thumbApp' => $this->app['thumbApp'],
  76. 'linkPc'=> $this->app['linkPc'],
  77. 'linkApp' => $this->app['linkApp'],
  78. 'listOrder' => 1
  79. ], [
  80. 'activeID'=>$this->app['activeID']
  81. ]);
  82. $model['activeID'] = $this->app['activeID'];
  83. }
  84. return Common::rm(1, '操作成功', [
  85. 'activeID'=>$model['activeID']
  86. ]);
  87. }
  88. public function activeGetList() {
  89. $map = [];
  90. if(isset($this->app['isOnLineApp']) && $this->app['isOnLineApp']) {
  91. $map['isOnLineApp'] = $this->app['isOnLineApp'];
  92. }
  93. if(isset($this->app['isOnLinePc']) && $this->app['isOnLinePc']) {
  94. $map['isOnLinePc'] = $this->app['isOnLinePc'];
  95. }
  96. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  97. $this->app['pageIndex'] = 1;
  98. }
  99. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  100. $this->app['pageItemCount'] = 10;
  101. }
  102. $count = Active::where($map)->count();
  103. $list = Active::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  104. if($list->isEmpty()) {
  105. return Common::rm(-2, '数据为空');
  106. }
  107. return Common::rm(1, '操作成功', [
  108. 'activeList'=>$list,
  109. 'count'=>$count,
  110. 'pageItemCount'=>$this->app['pageItemCount'],
  111. ]);
  112. }
  113. public function activeGetDetail() {
  114. $item = Active::get($this->app['activeID']);
  115. if(!$item) {
  116. return Common::rm(-32, '没有数据');
  117. }
  118. return Common::rm(1, '操作成功', [
  119. 'detail'=>$item
  120. ]);
  121. }
  122. /**
  123. * @api {post} market/activeActionOnlineApp 活动app上线
  124. * @apiVersion 1.0.0
  125. * @apiName activeActionOnlineApp
  126. * @apiDescription 活动app上线
  127. * @apiGroup Market
  128. *
  129. * @apiParam {Number} activeID activeID
  130. * @apiParamExample {json} 发送报文:
  131. {
  132. "activeID": 12
  133. }
  134. *
  135. * @apiSuccess {Object} detail active部分
  136. * @apiSuccess {Number} detail.isOnLineApp 状态
  137. * @apiSuccessExample {json} 返回json数据(举例):
  138. {
  139. "code": 1,
  140. "msg": "操作成功",
  141. "content": {
  142. detail:{
  143. "isOnLineApp": 1
  144. }
  145. }
  146. }
  147. * @apiUse CreateUserError
  148. */
  149. public function activeActionOnlineApp() {
  150. $item = Active::get($this->app['activeID']);
  151. if(!$item) {
  152. return Common::rm(-2, '没有数据');
  153. }
  154. $item['isOnLineApp'] = 1;
  155. $item->save();
  156. return Common::rm(1, '操作成功', [
  157. 'detail'=>$item->visible(['isOnLineApp'])
  158. ]);
  159. }
  160. /**
  161. * @api {post} market/activeActionOfflineApp 活动app下线
  162. * @apiVersion 1.0.0
  163. * @apiName activeActionOfflineApp
  164. * @apiDescription 活动pc下线
  165. * @apiGroup Market
  166. *
  167. * @apiParam {Number} activeID 活动ID
  168. * @apiParamExample {json} 发送报文:
  169. {
  170. "activeID": 12
  171. }
  172. *
  173. * @apiSuccess {Object} detail active部分
  174. * @apiSuccess {Number} detail.isOnLineApp 状态
  175. * @apiSuccessExample {json} 返回json数据(举例):
  176. {
  177. "code": 1,
  178. "msg": "操作成功",
  179. "content": {
  180. detail:{
  181. "isOnLineApp": 2
  182. }
  183. }
  184. }
  185. * @apiUse CreateUserError
  186. */
  187. public function activeActionOfflineApp() {
  188. $item = Active::get($this->app['activeID']);
  189. if(!$item) {
  190. return Common::rm(-2, '没有数据');
  191. }
  192. $item['isOnLineApp'] = 0;
  193. $item->save();
  194. return Common::rm(1, '操作成功', [
  195. 'detail'=>$item->visible(['isOnLineApp'])
  196. ]);
  197. }
  198. /**
  199. * @api {post} market/activeActionOnlinePc 活动pc上线
  200. * @apiVersion 1.0.0
  201. * @apiName activeActionOnlinePc
  202. * @apiDescription 活动pc上线
  203. * @apiGroup Market
  204. *
  205. * @apiParam {Number} activeID activeID
  206. * @apiParamExample {json} 发送报文:
  207. {
  208. "activeID": 12
  209. }
  210. *
  211. * @apiSuccess {Object} detail active部分
  212. * @apiSuccess {Number} detail.isOnLinePc 状态
  213. * @apiSuccessExample {json} 返回json数据(举例):
  214. {
  215. "code": 1,
  216. "msg": "操作成功",
  217. "content": {
  218. detail:{
  219. "isOnLinePc": 1
  220. }
  221. }
  222. }
  223. * @apiUse CreateUserError
  224. */
  225. public function activeActionOnlinePc() {
  226. $item = Active::get($this->app['activeID']);
  227. if(!$item) {
  228. return Common::rm(-2, '没有数据');
  229. }
  230. $item['isOnLinePc'] = 1;
  231. $item->save();
  232. return Common::rm(1, '操作成功', [
  233. 'detail'=>$item->visible(['isOnLinePc'])
  234. ]);
  235. }
  236. /**
  237. * @api {post} market/activeActionOfflinePc 活动pc下线
  238. * @apiVersion 1.0.0
  239. * @apiName activeActionOfflinePc
  240. * @apiDescription 活动pc下线
  241. * @apiGroup Market
  242. *
  243. * @apiParam {Number} activeID 活动ID
  244. * @apiParamExample {json} 发送报文:
  245. {
  246. "activeID": 12
  247. }
  248. *
  249. * @apiSuccess {Object} detail active部分
  250. * @apiSuccess {Number} detail.isOnLinePc 状态
  251. * @apiSuccessExample {json} 返回json数据(举例):
  252. {
  253. "code": 1,
  254. "msg": "操作成功",
  255. "content": {
  256. detail:{
  257. "isOnLinePc": 2
  258. }
  259. }
  260. }
  261. * @apiUse CreateUserError
  262. */
  263. public function activeActionOfflinePc() {
  264. $item = Active::get($this->app['activeID']);
  265. if(!$item) {
  266. return Common::rm(-2, '没有数据');
  267. }
  268. $item['isOnLinePc'] = 0;
  269. $item->save();
  270. return Common::rm(1, '操作成功', [
  271. 'detail'=>$item->visible(['isOnLinePc'])
  272. ]);
  273. }
  274. /**
  275. * @api {post} setting/activeActionDelete 删除活动条目
  276. * @apiVersion 1.0.0
  277. * @apiName activeActionDelete
  278. * @apiDescription 删除活动条目
  279. * @apiGroup Market
  280. *
  281. * @apiParam {Number} activeID activeID
  282. * @apiParamExample {json} 发送报文:
  283. {
  284. "activeID": 12
  285. }
  286. *
  287. * @apiSuccessExample {json} 返回json数据(举例):
  288. {
  289. "code": 1,
  290. "msg": "操作成功"
  291. }
  292. * @apiUse CreateUserError
  293. */
  294. public function activeActionDelete() {
  295. $model = Active::get($this->app['bannerID']);
  296. $model->delete();
  297. return Common::rm(1, '操作成功');
  298. }
  299. /************** 红包模块 ****************/
  300. public function hongbaoGetTypeList() {
  301. return Common::rm(1, '操作成功', [
  302. 'typeList'=>(new Hongbao())->getTypeList()
  303. ]);
  304. }
  305. public function hongbaoUpdate() {
  306. if(!isset($this->app['hongbaoID']) ||!$this->app['hongbaoID']) {
  307. $model = Hongbao::create([
  308. 'title' => $this->app['title'],
  309. 'typeID' => $this->app['typeID'],
  310. 'note' => $this->app['note'],
  311. 'minDay' => $this->app['minDay'],
  312. 'maxDay' => $this->app['maxDay'],
  313. 'minMoney' => $this->app['minMoney'],
  314. 'maxMoney' => $this->app['maxMoney'],
  315. 'effectTimeType' => 1,
  316. 'year' => $this->app['year'],
  317. 'money'=> $this->app['money'],
  318. 'term' => $this->app['term'],
  319. 'subjectTypeID' => 0,
  320. 'totalNumber' => isset($this->app['totalNumber']) && $this->app['totalNumber'] ? $this->app['totalNumber'] : 0,
  321. 'status'=>2
  322. ]);
  323. }
  324. else {
  325. $model = Hongbao::update([
  326. 'title' => $this->app['title'],
  327. 'note' => $this->app['note'],
  328. 'minDay' => $this->app['minDay'],
  329. 'maxDay' => $this->app['maxDay'],
  330. 'minMoney' => $this->app['minMoney'],
  331. 'maxMoney' => $this->app['maxMoney'],
  332. 'term' => $this->app['term'],
  333. 'totalNumber' => isset($this->app['totalNumber']) && $this->app['totalNumber'] ? $this->app['totalNumber'] : 0,
  334. ], [
  335. 'hongbaoID'=>$this->app['hongbaoID']
  336. ]);
  337. $model['hongbaoID'] = $this->app['hongbaoID'];
  338. }
  339. return Common::rm(1, '操作成功', [
  340. 'hongbaoID'=>$model['hongbaoID']
  341. ]);
  342. }
  343. public function hongbaoGetDetail() {
  344. $item = Hongbao::get($this->app['hongbaoID']);
  345. if(!$item) {
  346. return Common::rm(-32, '没有数据');
  347. }
  348. return Common::rm(1, '操作成功', [
  349. 'detail'=>$item
  350. ]);
  351. }
  352. public function hongbaoGetList() {
  353. $map = [];
  354. if(isset($this->app['isOnLineApp']) && $this->app['isOnLineApp']) {
  355. $map['isOnLineApp'] = $this->app['isOnLineApp'];
  356. }
  357. if(isset($this->app['isOnLinePc']) && $this->app['isOnLinePc']) {
  358. $map['isOnLinePc'] = $this->app['isOnLinePc'];
  359. }
  360. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  361. $this->app['pageIndex'] = 1;
  362. }
  363. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  364. $this->app['pageItemCount'] = 10;
  365. }
  366. $count = Hongbao::where($map)->count();
  367. $list = Hongbao::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  368. if($list->isEmpty()) {
  369. return Common::rm(-2, '数据为空');
  370. }
  371. $list->append(['typeName', 'statusText']);
  372. return Common::rm(1, '操作成功', [
  373. 'hongbaoList'=>$list,
  374. 'count'=>$count,
  375. 'pageItemCount'=>$this->app['pageItemCount'],
  376. ]);
  377. }
  378. public function hongbaoActionOnline() {
  379. $item = Hongbao::get($this->app['hongbaoID']);
  380. if(!$item) {
  381. return Common::rm(-2, '没有数据');
  382. }
  383. $item['status'] = 1;
  384. $item->save();
  385. return Common::rm(1, '操作成功', [
  386. 'detail'=>$item->append(['statusText'])->visible(['status'])
  387. ]);
  388. }
  389. public function hongbaoActionOffline() {
  390. $item = Hongbao::get($this->app['hongbaoID']);
  391. if(!$item) {
  392. return Common::rm(-2, '没有数据');
  393. }
  394. $item['status'] = 2;
  395. $item->save();
  396. return Common::rm(1, '操作成功', [
  397. 'detail'=>$item->append(['statusText'])->visible(['status'])
  398. ]);
  399. }
  400. /************** 红包派送计划模块 ****************/
  401. public function hongbaoPlanGetTypeList() {
  402. return Common::rm(1, '操作成功', [
  403. 'typeList'=>(new HongbaoPlan())->getTypeList()
  404. ]);
  405. }
  406. public function hongbaoPlanUpdate() {
  407. if(!isset($this->app['hongbaoPlanID']) ||!$this->app['hongbaoPlanID']) {
  408. $model = HongbaoPlan::create([
  409. 'title' => $this->app['title'],
  410. 'typeID' => $this->app['typeID'],
  411. 'note' => $this->app['note'],
  412. 'hongbaoID' => $this->app['hongbaoID'],
  413. 'status' => HongbaoPlan::STATUS_ONLINE,
  414. 'sendTime' => isset($this->app['sendTime']) && $this->app['sendTime'] ? Common::datetotime($this->app['sendTime']) : 0
  415. ]);
  416. }
  417. else {
  418. $model = Hongbao::update([
  419. 'title' => $this->app['title'],
  420. 'note' => $this->app['note']
  421. ], [
  422. 'hongbaoPlanID'=>$this->app['hongbaoPlanID']
  423. ]);
  424. $model['hongbaoPlanID'] = $this->app['hongbaoPlanID'];
  425. }
  426. return Common::rm(1, '操作成功', [
  427. 'hongbaoPlanID'=>$model['hongbaoPlanID']
  428. ]);
  429. }
  430. public function hongbaoPlanGetDetail() {
  431. $item = HongBaoPlan::get($this->app['hongbaoPlanID']);
  432. if(!$item) {
  433. return Common::rm(-32, '没有数据');
  434. }
  435. return Common::rm(1, '操作成功', [
  436. 'detail'=>$item
  437. ]);
  438. }
  439. public function hongbaoPlanGetList() {
  440. $map = [];
  441. if(isset($this->app['typeID']) && $this->app['typeID']) {
  442. $map['typeID'] = $this->app['typeID'];
  443. }
  444. if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
  445. $this->app['pageIndex'] = 1;
  446. }
  447. if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
  448. $this->app['pageItemCount'] = 10;
  449. }
  450. $count = HongbaoPlan::where($map)->count();
  451. $list = HongbaoPlan::with(['hongbao'])->where($map)->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
  452. if($list->isEmpty()) {
  453. return Common::rm(-2, '数据为空');
  454. }
  455. $list->append(['typeName']);
  456. return Common::rm(1, '操作成功', [
  457. 'hongbaoPlanList'=>$list,
  458. 'count'=>$count,
  459. 'pageItemCount'=>$this->app['pageItemCount'],
  460. ]);
  461. }
  462. public function hongbaoPlanActionDelete() {
  463. $model = HongBaoPlan::get($this->app['hongbaoPlanID']);
  464. $model->delete();
  465. return Common::rm(1, '操作成功');
  466. }
  467. public function hongbaoPlanMade() {
  468. $hongbaoPlan = new HongbaoPlan();
  469. $user = User::get([
  470. 'mobile'=>$this->app['mobile']
  471. ]);
  472. /*if(!$user) {
  473. return Common::rm(-2, '用户不存在');
  474. }*/
  475. if(!$hongbaoPlan->sendUser($user, $this->app['hongbaoIDS'], $this->master['mobile'], '年底加息约标', $this->app['mobile'])) {
  476. return Common::rm(-3, '不存在红包');
  477. }
  478. return Common::rm(1, '操作成功');
  479. }
  480. }