123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qisse
- * Date: 2017/6/27
- * Time: 20:02
- */
- namespace app\master\logic;
- use app\core\model\Active;
- use app\core\model\Hongbao;
- use app\core\model\HongbaoPlan;
- use app\core\model\Sms;
- use app\core\model\User;
- use tool\Common;
- class Market extends Base
- {
- /**
- * @api {post} market/activeUpdate 新增/更新active统一接口
- * @apiVersion 1.0.0
- * @apiName activeUpdate
- * @apiDescription 新增/更新active统一接口
- * @apiGroup Setting
- *
- * @apiParam {Number} activeID 类型ID,更新时为必传字段,新增时保持bannerID必须为0
- * @apiParam {String} thumbPc pc图片url
- * @apiParam {String} thumbApp app图片Url
- * @apiParam {String} linkPc 图片url
- * @apiParam {String} linkApp 图片url
- * @apiParam {String} title 标题
- * @apiParam {String} note 备注
- * @apiParam {String} {isOnLinePc=0,1} pc是否在线上,0-线下,1线上
- * @apiParam {String} {isOnLineApp=0,1} app是否在线上,0-线下,1线上
- * @apiParamExample {json} 发送报文:
- {
- "activeID": 2,
- "thumbPc": "http://www.baidu.com/image.jpg",
- "thumbApp": "http://www.baidu.com/",
- "linkPc": "http://www.baidu.com/image.jpg",
- "linkApp": "http://www.baidu.com/",
- "title": "春旗佳节游泳包",
- "note": "春旗佳节游泳包撒的发生的发生大法师打发斯蒂芬",
- "isOnLinePc": 0,
- "isOnLineApp": 1
- }
- *
- * @apiSuccess {Number} bannerID bannerID
- * @apiSuccessExample {json} 返回json数据(举例):
- {
- "code": 1,
- "msg": "操作成功",
- "content": {
- "activeID": 12
- }
- }
- * @apiUse CreateUserError
- */
- public function activeUpdate()
- {
- if(!isset($this->app['activeID']) ||!$this->app['activeID']) {
- $model = Active::create([
- 'title' => $this->app['title'],
- 'note' => $this->app['note'],
- 'thumbPc' => $this->app['thumbPc'],
- 'thumbApp' => $this->app['thumbApp'],
- 'linkPc'=> $this->app['linkPc'],
- 'linkApp' => $this->app['linkApp'],
- 'listOrder' => 1
- ]);
- }
- else {
- $model = Active::update([
- 'title' => $this->app['title'],
- 'note' => $this->app['note'],
- 'thumbPc' => $this->app['thumbPc'],
- 'thumbApp' => $this->app['thumbApp'],
- 'linkPc'=> $this->app['linkPc'],
- 'linkApp' => $this->app['linkApp'],
- 'listOrder' => 1
- ], [
- 'activeID'=>$this->app['activeID']
- ]);
- $model['activeID'] = $this->app['activeID'];
- }
- return Common::rm(1, '操作成功', [
- 'activeID'=>$model['activeID']
- ]);
- }
- public function activeGetList() {
- $map = [];
- if(isset($this->app['isOnLineApp']) && $this->app['isOnLineApp']) {
- $map['isOnLineApp'] = $this->app['isOnLineApp'];
- }
- if(isset($this->app['isOnLinePc']) && $this->app['isOnLinePc']) {
- $map['isOnLinePc'] = $this->app['isOnLinePc'];
- }
- if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
- $this->app['pageIndex'] = 1;
- }
- if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
- $this->app['pageItemCount'] = 10;
- }
- $count = Active::where($map)->count();
- $list = Active::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
- if($list->isEmpty()) {
- return Common::rm(-2, '数据为空');
- }
- return Common::rm(1, '操作成功', [
- 'activeList'=>$list,
- 'count'=>$count,
- 'pageItemCount'=>$this->app['pageItemCount'],
- ]);
- }
- public function activeGetDetail() {
- $item = Active::get($this->app['activeID']);
- if(!$item) {
- return Common::rm(-32, '没有数据');
- }
- return Common::rm(1, '操作成功', [
- 'detail'=>$item
- ]);
- }
- /**
- * @api {post} market/activeActionOnlineApp 活动app上线
- * @apiVersion 1.0.0
- * @apiName activeActionOnlineApp
- * @apiDescription 活动app上线
- * @apiGroup Market
- *
- * @apiParam {Number} activeID activeID
- * @apiParamExample {json} 发送报文:
- {
- "activeID": 12
- }
- *
- * @apiSuccess {Object} detail active部分
- * @apiSuccess {Number} detail.isOnLineApp 状态
- * @apiSuccessExample {json} 返回json数据(举例):
- {
- "code": 1,
- "msg": "操作成功",
- "content": {
- detail:{
- "isOnLineApp": 1
- }
- }
- }
- * @apiUse CreateUserError
- */
- public function activeActionOnlineApp() {
- $item = Active::get($this->app['activeID']);
- if(!$item) {
- return Common::rm(-2, '没有数据');
- }
- $item['isOnLineApp'] = 1;
- $item->save();
- return Common::rm(1, '操作成功', [
- 'detail'=>$item->visible(['isOnLineApp'])
- ]);
- }
- /**
- * @api {post} market/activeActionOfflineApp 活动app下线
- * @apiVersion 1.0.0
- * @apiName activeActionOfflineApp
- * @apiDescription 活动pc下线
- * @apiGroup Market
- *
- * @apiParam {Number} activeID 活动ID
- * @apiParamExample {json} 发送报文:
- {
- "activeID": 12
- }
- *
- * @apiSuccess {Object} detail active部分
- * @apiSuccess {Number} detail.isOnLineApp 状态
- * @apiSuccessExample {json} 返回json数据(举例):
- {
- "code": 1,
- "msg": "操作成功",
- "content": {
- detail:{
- "isOnLineApp": 2
- }
- }
- }
- * @apiUse CreateUserError
- */
- public function activeActionOfflineApp() {
- $item = Active::get($this->app['activeID']);
- if(!$item) {
- return Common::rm(-2, '没有数据');
- }
- $item['isOnLineApp'] = 0;
- $item->save();
- return Common::rm(1, '操作成功', [
- 'detail'=>$item->visible(['isOnLineApp'])
- ]);
- }
- /**
- * @api {post} market/activeActionOnlinePc 活动pc上线
- * @apiVersion 1.0.0
- * @apiName activeActionOnlinePc
- * @apiDescription 活动pc上线
- * @apiGroup Market
- *
- * @apiParam {Number} activeID activeID
- * @apiParamExample {json} 发送报文:
- {
- "activeID": 12
- }
- *
- * @apiSuccess {Object} detail active部分
- * @apiSuccess {Number} detail.isOnLinePc 状态
- * @apiSuccessExample {json} 返回json数据(举例):
- {
- "code": 1,
- "msg": "操作成功",
- "content": {
- detail:{
- "isOnLinePc": 1
- }
- }
- }
- * @apiUse CreateUserError
- */
- public function activeActionOnlinePc() {
- $item = Active::get($this->app['activeID']);
- if(!$item) {
- return Common::rm(-2, '没有数据');
- }
- $item['isOnLinePc'] = 1;
- $item->save();
- return Common::rm(1, '操作成功', [
- 'detail'=>$item->visible(['isOnLinePc'])
- ]);
- }
- /**
- * @api {post} market/activeActionOfflinePc 活动pc下线
- * @apiVersion 1.0.0
- * @apiName activeActionOfflinePc
- * @apiDescription 活动pc下线
- * @apiGroup Market
- *
- * @apiParam {Number} activeID 活动ID
- * @apiParamExample {json} 发送报文:
- {
- "activeID": 12
- }
- *
- * @apiSuccess {Object} detail active部分
- * @apiSuccess {Number} detail.isOnLinePc 状态
- * @apiSuccessExample {json} 返回json数据(举例):
- {
- "code": 1,
- "msg": "操作成功",
- "content": {
- detail:{
- "isOnLinePc": 2
- }
- }
- }
- * @apiUse CreateUserError
- */
- public function activeActionOfflinePc() {
- $item = Active::get($this->app['activeID']);
- if(!$item) {
- return Common::rm(-2, '没有数据');
- }
- $item['isOnLinePc'] = 0;
- $item->save();
- return Common::rm(1, '操作成功', [
- 'detail'=>$item->visible(['isOnLinePc'])
- ]);
- }
- /**
- * @api {post} setting/activeActionDelete 删除活动条目
- * @apiVersion 1.0.0
- * @apiName activeActionDelete
- * @apiDescription 删除活动条目
- * @apiGroup Market
- *
- * @apiParam {Number} activeID activeID
- * @apiParamExample {json} 发送报文:
- {
- "activeID": 12
- }
- *
- * @apiSuccessExample {json} 返回json数据(举例):
- {
- "code": 1,
- "msg": "操作成功"
- }
- * @apiUse CreateUserError
- */
- public function activeActionDelete() {
- $model = Active::get($this->app['bannerID']);
- $model->delete();
- return Common::rm(1, '操作成功');
- }
- /************** 红包模块 ****************/
- public function hongbaoGetTypeList() {
- return Common::rm(1, '操作成功', [
- 'typeList'=>(new Hongbao())->getTypeList()
- ]);
- }
- public function hongbaoUpdate() {
- if(!isset($this->app['hongbaoID']) ||!$this->app['hongbaoID']) {
- $model = Hongbao::create([
- 'title' => $this->app['title'],
- 'typeID' => $this->app['typeID'],
- 'note' => $this->app['note'],
- 'minDay' => $this->app['minDay'],
- 'maxDay' => $this->app['maxDay'],
- 'minMoney' => $this->app['minMoney'],
- 'maxMoney' => $this->app['maxMoney'],
- 'effectTimeType' => 1,
- 'year' => $this->app['year'],
- 'money'=> $this->app['money'],
- 'term' => $this->app['term'],
- 'subjectTypeID' => 0,
- 'totalNumber' => isset($this->app['totalNumber']) && $this->app['totalNumber'] ? $this->app['totalNumber'] : 0,
- 'status'=>2
- ]);
- }
- else {
- $model = Hongbao::update([
- 'title' => $this->app['title'],
- 'note' => $this->app['note'],
- 'minDay' => $this->app['minDay'],
- 'maxDay' => $this->app['maxDay'],
- 'minMoney' => $this->app['minMoney'],
- 'maxMoney' => $this->app['maxMoney'],
- 'term' => $this->app['term'],
- 'totalNumber' => isset($this->app['totalNumber']) && $this->app['totalNumber'] ? $this->app['totalNumber'] : 0,
- ], [
- 'hongbaoID'=>$this->app['hongbaoID']
- ]);
- $model['hongbaoID'] = $this->app['hongbaoID'];
- }
- return Common::rm(1, '操作成功', [
- 'hongbaoID'=>$model['hongbaoID']
- ]);
- }
- public function hongbaoGetDetail() {
- $item = Hongbao::get($this->app['hongbaoID']);
- if(!$item) {
- return Common::rm(-32, '没有数据');
- }
- return Common::rm(1, '操作成功', [
- 'detail'=>$item
- ]);
- }
- public function hongbaoGetList() {
- $map = [];
- if(isset($this->app['isOnLineApp']) && $this->app['isOnLineApp']) {
- $map['isOnLineApp'] = $this->app['isOnLineApp'];
- }
- if(isset($this->app['isOnLinePc']) && $this->app['isOnLinePc']) {
- $map['isOnLinePc'] = $this->app['isOnLinePc'];
- }
- if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
- $this->app['pageIndex'] = 1;
- }
- if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
- $this->app['pageItemCount'] = 10;
- }
- $count = Hongbao::where($map)->count();
- $list = Hongbao::where($map)->order('addTime desc')->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
- if($list->isEmpty()) {
- return Common::rm(-2, '数据为空');
- }
- $list->append(['typeName', 'statusText']);
- return Common::rm(1, '操作成功', [
- 'hongbaoList'=>$list,
- 'count'=>$count,
- 'pageItemCount'=>$this->app['pageItemCount'],
- ]);
- }
- public function hongbaoActionOnline() {
- $item = Hongbao::get($this->app['hongbaoID']);
- if(!$item) {
- return Common::rm(-2, '没有数据');
- }
- $item['status'] = 1;
- $item->save();
- return Common::rm(1, '操作成功', [
- 'detail'=>$item->append(['statusText'])->visible(['status'])
- ]);
- }
- public function hongbaoActionOffline() {
- $item = Hongbao::get($this->app['hongbaoID']);
- if(!$item) {
- return Common::rm(-2, '没有数据');
- }
- $item['status'] = 2;
- $item->save();
- return Common::rm(1, '操作成功', [
- 'detail'=>$item->append(['statusText'])->visible(['status'])
- ]);
- }
- /************** 红包派送计划模块 ****************/
- public function hongbaoPlanGetTypeList() {
- return Common::rm(1, '操作成功', [
- 'typeList'=>(new HongbaoPlan())->getTypeList()
- ]);
- }
- public function hongbaoPlanUpdate() {
- if(!isset($this->app['hongbaoPlanID']) ||!$this->app['hongbaoPlanID']) {
- $model = HongbaoPlan::create([
- 'title' => $this->app['title'],
- 'typeID' => $this->app['typeID'],
- 'note' => $this->app['note'],
- 'hongbaoID' => $this->app['hongbaoID'],
- 'status' => HongbaoPlan::STATUS_ONLINE,
- 'sendTime' => isset($this->app['sendTime']) && $this->app['sendTime'] ? Common::datetotime($this->app['sendTime']) : 0
- ]);
- }
- else {
- $model = Hongbao::update([
- 'title' => $this->app['title'],
- 'note' => $this->app['note']
- ], [
- 'hongbaoPlanID'=>$this->app['hongbaoPlanID']
- ]);
- $model['hongbaoPlanID'] = $this->app['hongbaoPlanID'];
- }
- return Common::rm(1, '操作成功', [
- 'hongbaoPlanID'=>$model['hongbaoPlanID']
- ]);
- }
- public function hongbaoPlanGetDetail() {
- $item = HongBaoPlan::get($this->app['hongbaoPlanID']);
- if(!$item) {
- return Common::rm(-32, '没有数据');
- }
- return Common::rm(1, '操作成功', [
- 'detail'=>$item
- ]);
- }
- public function hongbaoPlanGetList() {
- $map = [];
- if(isset($this->app['typeID']) && $this->app['typeID']) {
- $map['typeID'] = $this->app['typeID'];
- }
- if(!isset($this->app['pageIndex']) || !$this->app['pageIndex']) {
- $this->app['pageIndex'] = 1;
- }
- if(!isset($this->app['pageItemCount']) || !$this->app['pageItemCount']) {
- $this->app['pageItemCount'] = 10;
- }
- $count = HongbaoPlan::where($map)->count();
- $list = HongbaoPlan::with(['hongbao'])->where($map)->limit(($this->app['pageIndex'] - 1) * $this->app['pageItemCount'], $this->app['pageItemCount'])->order('addTime desc')->select();
- if($list->isEmpty()) {
- return Common::rm(-2, '数据为空');
- }
- $list->append(['typeName']);
- return Common::rm(1, '操作成功', [
- 'hongbaoPlanList'=>$list,
- 'count'=>$count,
- 'pageItemCount'=>$this->app['pageItemCount'],
- ]);
- }
- public function hongbaoPlanActionDelete() {
- $model = HongBaoPlan::get($this->app['hongbaoPlanID']);
- $model->delete();
- return Common::rm(1, '操作成功');
- }
- public function hongbaoPlanMade() {
- $hongbaoPlan = new HongbaoPlan();
- $user = User::get([
- 'mobile'=>$this->app['mobile']
- ]);
- /*if(!$user) {
- return Common::rm(-2, '用户不存在');
- }*/
- if(!$hongbaoPlan->sendUser($user, $this->app['hongbaoIDS'], $this->master['mobile'], '年底加息约标', $this->app['mobile'])) {
- return Common::rm(-3, '不存在红包');
- }
- return Common::rm(1, '操作成功');
- }
- }
|