审查视图

application/api/controller/User.php 99.9 KB
郭盛 authored
1 2 3 4 5 6 7
<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
8
use function fast\e;
郭盛 authored
9
use fast\Random;
郭盛 authored
10
use function GuzzleHttp\Promise\promise_for;
郭盛 authored
11 12
use think\Db;
use think\Validate;
郭盛 authored
13
use fast\Http;
郭盛 authored
14 15 16 17 18 19

/**
 * 个人中心
 */
class User extends Api
{
郭盛 authored
20
    protected $noNeedLogin = ['login','index','type','mine','car','cover','words','share','change'];
郭盛 authored
21
    protected $noNeedRight = '*';
郭盛 authored
22
    protected $uid = '';
郭盛 authored
23 24 25 26

    public function _initialize()
    {
        parent::_initialize();
郭盛 authored
27
        $this->uid = $this->auth->getUserId();
郭盛 authored
28 29 30 31 32 33 34 35 36 37
    }

    /**
     * @ApiTitle    (小程序登录)
     * @ApiSummary  (小程序登录)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/login)
     * @ApiParams   (name="code", type="string", required=true, description="小程序code")
     * @ApiParams   (name="nickname", type="string", required=true, description="小程序昵称")
     * @ApiParams   (name="avatar", type="string", required=true, description="小程序头像")
郭盛 authored
38
     * @ApiParams   (name="type", type="inter", required=true, description="是否为苹果用户0否1是")
郭盛 authored
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
     * @ApiReturn({
    "code": 1,
    "msg": "登录成功",
    "time": "1553839125",
    "data": {
    "token": "677afb39-1a4f-4492-84d3-0bcf32016b8a",//token
    "user_id": 27,//用户id
    "createtime": 1553839125,//登录时间
    "expiretime": 1556431125,//token失效时间
    "expires_in": 2592000//token失效剩余时间(单位s)
    "openid": 1485212522522//openid
    })
     */
    public function login(){
        if($this->request->isPost()){
            //小程序配置
            $config =  config('verify.raw');
郭盛 authored
56
            //小程序传递数据,包含昵称,头像,code,是否为苹果用户参数
郭盛 authored
57 58 59
            $raw_data = $this->request->post();
            //验证表数据
            $rule = config('verify.user');
郭盛 authored
60
            $validate = new Validate($rule['rule'],$rule['msg']);
郭盛 authored
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
            if (!$validate->check($raw_data)) {
                $this->error($validate->getError());
            }
            $params = [
                'appid'      => $config['app_id'],
                'secret'     => $config['secret'],
                'js_code'    => $raw_data['code'],
                'grant_type' => 'authorization_code'
            ];
            $result = Http::sendRequest("https://api.weixin.qq.com/sns/jscode2session", $params, 'GET');
            if ($result['ret']) {
                $json = (array)json_decode($result['msg'], true);
                if (isset($json['openid'])) {
                    $result = [
                        'openid' => $json['openid'],
                        'nickname' => $raw_data['nickname'],
                        'avatar' => $raw_data['avatar']
                    ];
                    $ret = $this->auth->login($result);
                    if ($ret) {
                        $data = $this->auth->getUserinfo();
郭盛 authored
82 83 84
                        if(!empty($raw_data['type'])){
                            Db::name('user')->where('id',$data['id'])->update(['type'=>$raw_data['type']]);
                        }
郭盛 authored
85 86 87 88 89 90 91 92 93 94 95 96 97 98
                        $this->success('登录成功', $data);
                    }else {
                        $this->error($this->auth->getError());
                    }
                } else {
                    $this->error("登录失败",$json);
                }
            }
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
郭盛 authored
99 100
     * @ApiTitle    (首页flash接口)
     * @ApiSummary  (首页flash接口)
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/cover)

     * @ApiReturn   ({
        'code':'1',
        'msg':'返回成功',
        "time": "1571492001",
        "data": {
        "thumbnail": //封面图地址
        "createtime":  //创建时间
        "updatetime":  //修改时间
        }
        })
     */
    public function cover()
    {
        $rule = config('verify.path');
        $data = Db::name('cover')
            ->field('id,thumbnail')
            ->where('id',1)
            ->find();
        $data['thumbnail'] = $rule.$data['thumbnail'];
        $this->success('success',$data);
    }
郭盛 authored
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    /**
     * @ApiTitle    (分享封面接口)
     * @ApiSummary  (分享封面接口)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/share)

     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "time": "1571492001",
    "data": {
    "thumbnail": //分享图地址
    "createtime":  //创建时间
    "updatetime":  //修改时间
    }
    })
     */
    public function share()
    {
        $rule = config('verify.path');
        $data = Db::name('share')
            ->where('id',1)
            ->field('thumbnail')
            ->find();
        $data['thumbnail'] = $rule.$data['thumbnail'];
        $this->success('SUCCESS',$data);
    }
154 155

    /**
郭盛 authored
156 157
     * @ApiTitle    (首页视频、图片、精美大片入口)
     * @ApiSummary  (首页视频、图片、精美大片入口)
郭盛 authored
158 159 160 161 162
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/index)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturn   ({
    'code':'1',
郭盛 authored
163 164 165
    'msg':'返回成功',
    "time": "1571492001",
        "data": {
郭盛 authored
166 167 168
        "thumbnail": //大片封面图地址
        "iamge":  //图片地址
        "pic":  //精美大片地址
郭盛 authored
169
        }
郭盛 authored
170 171 172 173
    })
     */
    public function index()
    {
郭盛 authored
174
        $rule = config('verify.path');
郭盛 authored
175 176
        $data = Db::name('feng')
            ->field('id,thumbnail,image,pic')
郭盛 authored
177
            ->find();
郭盛 authored
178 179 180 181

        $res['thumbnail'] = $rule.$data['thumbnail'];
        $res['pic'] = $rule.$data['pic'];
        $res['image'] = $rule.$data['image'];
郭盛 authored
182
        $this->success('SUCCESS',$res);
郭盛 authored
183 184
    }
郭盛 authored
185 186 187
    /**
     * @ApiTitle    (地区分类)
     * @ApiSummary  (地区分类)
郭盛 authored
188
     * @ApiMethod   (POST)
郭盛 authored
189 190 191 192 193 194 195 196
     * @ApiRoute    (/api/user/type)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
郭盛 authored
197 198 199 200
        "id": 4,//分类id
        "area_name": //分类名称
        "thumbnail": //图片
        }
郭盛 authored
201 202 203 204
    })
     */
    public function type()
    {
郭盛 authored
205
        $rule = config('verify.path');
郭盛 authored
206 207 208 209
        $data = Db::name('type')
            ->field('id,area_name,thumbnail')
            ->order('id desc')
            ->select();
郭盛 authored
210 211 212
        foreach ($data as &$v){
            $v['thumbnail'] = $rule.$v['thumbnail'];
        }
郭盛 authored
213 214 215
        $this->success('SUCCESS',$data);
    }
郭盛 authored
216
    /**
郭盛 authored
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
     * @ApiTitle    (图片分类(类型))
     * @ApiSummary  (图片分类(类型))
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/pictype)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
        "id": 4,//分类id
        "typename": //分类名称
        "thumbnail": //图片
    }
    })
     */
    public function pictype()
    {
        $rule = config('verify.path');
        $data = Db::name('pictype')
            ->field('id,typename,thumbnail')
            ->select();
        foreach ($data as &$v){
            $v['thumbnail'] = $rule.$v['thumbnail'];
        }
        $this->success('SUCCESS',$data);
    }

    /**
郭盛 authored
247 248 249 250 251
     * @ApiTitle    (搜索页)
     * @ApiSummary  (搜索页)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/search)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
郭盛 authored
252
     *
253
     * @ApiParams   (name="type_id", type="inter", required=false, description="视频/图片(视频为1 图片为2)")
郭盛 authored
254
     * @ApiParams   (name="keyword", type="string", required=true, description="关键字(多个用空格分开)")
255 256
     * @ApiParams   (name="address", type="string", required=true, description="地名关键词数组")
     * @ApiParams   (name="text", type="string", required=true, description="内容关键词数组")
郭盛 authored
257
     * @ApiParams   (name="price", type="string", required=true, description="价格数组")
郭盛 authored
258 259
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
郭盛 authored
260
     * @ApiReturn({
郭盛 authored
261 262 263 264 265 266 267 268
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": 4,//视频id/图片id,
            "thumbnail": //视频封面图地址/图片地址,
            "video": //视频路径/精美大片视频路径,
        }
郭盛 authored
269 270 271 272
    })
     */
    public function search()
    {
郭盛 authored
273
        $user_id = $this->uid;
郭盛 authored
274 275
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
郭盛 authored
276
        $rule = config('verify.path');
277 278
        $param = $this->request->param();
        if(empty($param['type_id'])){
郭盛 authored
279 280
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
郭盛 authored
281 282 283
        //判断如果传递过来用户输入关键词不为空
        $where_shu = [];
        if(!empty($param['keyword'])){
郭盛 authored
284
            $shu = explode(' ',$param['keyword']);
郭盛 authored
285 286 287 288 289
            foreach ($shu as $k=>$v){
                if(!$v){
                    unset($shu[$k]);
                }
            }
郭盛 authored
290 291 292 293 294 295 296 297 298
            if($param['type_id'] == 1){
                //定义一个空数组
                $ids = [];
                foreach ($shu as &$v){
                    $id1 = Db::name('video')
                        ->where('keyword','like',"%$v%")
                        ->whereOr('title','like',"%$v%")
                        ->column('id');
                    foreach ($id1 as $val){
郭盛 authored
299 300
                        array_push($ids,$val);
                    }
郭盛 authored
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
                    $id2 = Db::name('words')
                        ->where('name',$v)
                        ->field('id,type')
                        ->find();
                    if(!empty($id2)){
                        if($id2['type'] == 1){
                            $a = Db::name('video')
                                ->where('address_ids','like','%,'.$id2['id'].',%')
                                ->order('is_show desc')
                                ->column('id');
                        }elseif ($id2['type'] == 2){
                            $a = Db::name('video')
                                ->where('text_ids','like','%,'.$id2['id'].',%')
                                ->order('is_show desc')
                                ->column('id');
                        }
                        foreach ($a as $val){
                            array_push($ids,$val);
                        }
                    }
                }
                $ids2 = array_unique($ids);
                if($ids2 === $ids){
                    $result = $ids;
                }else{
                    $result=array_diff_assoc($ids,$ids2);
郭盛 authored
327 328 329 330
                }
                $data = Db::name('video')
                    ->whereIn('id',$result)
                    ->field('id,title,thumbnail')
郭盛 authored
331
                    ->order('is_show desc')
郭盛 authored
332 333 334 335 336 337 338
                    ->page($page,$pageNum)
                    ->select();
                foreach ($data as &$v){
                    $v['thumbnail'] = $rule.$v['thumbnail'];
                }
                $this->success('success',$data);
            }else{
郭盛 authored
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
                //定义一个空数组
                $ids = [];
                foreach ($shu as &$v){
                    $id1 = Db::name('pic')
                        ->where('keyword','like',"%$v%")
                        ->whereOr('title','like',"%$v%")
                        ->column('id');
                    foreach ($id1 as $val){
                        array_push($ids,$val);
                    }
                    $id2 = Db::name('words')
                        ->where('name',$v)
                        ->field('id,type')
                        ->find();
                    if(!empty($id2)){
                        if($id2['type'] == 1){
                            $a = Db::name('pic')
                                ->where('address_ids','like','%,'.$id2['id'].',%')
                                ->order('is_show desc')
                                ->column('id');
                        }elseif ($id2['type'] == 2){
                            $a = Db::name('pic')
                                ->where('text_ids','like','%,'.$id2['id'].',%')
                                ->order('is_show desc')
                                ->column('id');
                        }
                        foreach ($a as $val){
                            array_push($ids,$val);
                        }
                    }
                }
                $ids2 = array_unique($ids);
                if($ids2 === $ids){
                    $result = $ids;
                }else{
                    $result=array_diff_assoc($ids,$ids2);
                }
郭盛 authored
376 377 378
                $data = Db::name('pic')
                    ->whereIn('id',$result)
                    ->field('id,title,thumbnail')
郭盛 authored
379
                    ->order('is_show desc')
郭盛 authored
380 381 382 383 384 385 386
                    ->page($page,$pageNum)
                    ->select();
                foreach ($data as &$v){
                    $v['thumbnail'] = $rule.$v['thumbnail'];
                }
                $this->success('success',$data);
            }
郭盛 authored
387 388
        }
郭盛 authored
389
        //判断如果传递过来地名关键词不为空
郭盛 authored
390
        $where_address = [];
郭盛 authored
391
        if(!empty($param['address'])){
郭盛 authored
392 393
            $address = $param['address'];
            $where_address = function ($query_address) use ($address) {
郭盛 authored
394 395
                $a = Db::name('words')->where('id',$address)->field('id,name')->find();
                $query_address->where('address_ids','like','%,'.$address.',%')->whereor('keyword','like',"%$a[name]%");
郭盛 authored
396
            };
郭盛 authored
397
        }
郭盛 authored
398 399

        //判断如果传递过来内容关键词不为空
郭盛 authored
400
        $where_text = [];
郭盛 authored
401
        if(!empty($param['text'])){
郭盛 authored
402 403
            $text = $param['text'];
            $where_text = function ($query_text) use ($text) {
郭盛 authored
404 405
                $a = Db::name('words')->where('id',$text)->field('id,name')->find();
                $query_text->where('text_ids','like','%,'.$text.',%')->whereor('keyword','like',"%$a[name]%");
郭盛 authored
406
            };
郭盛 authored
407
        }
郭盛 authored
408
郭盛 authored
409
郭盛 authored
410 411 412 413 414
        //判断如果传递过来价格关键词不为空
        $where_price = [];
        if(!empty($param['price'])){
            $price = $param['price'];
            $where_price = function ($query_price) use ($price) {
郭盛 authored
415
                    $query_price->where('price',$price);
郭盛 authored
416 417
            };
        }
郭盛 authored
418
郭盛 authored
419
        if($param['type_id'] == 1){
郭盛 authored
420
            $ids = Db::name('video')->where($where_shu)->where($where_address)->where($where_text)->where($where_price)->order('is_show desc')->column('id');
郭盛 authored
421 422 423
            $data = Db::name('video')
                ->whereIn('id',$ids)
                ->field('id,title,thumbnail')
郭盛 authored
424
                ->order('is_show desc')
郭盛 authored
425 426 427 428 429 430 431
                ->page($page,$pageNum)
                ->select();
            foreach ($data as &$v){
                $v['thumbnail'] = $rule.$v['thumbnail'];
            }
            $this->success('success',$data);
        }else{
郭盛 authored
432
            $ids = Db::name('pic')->where($where_shu)->where($where_address)->where($where_text)->where($where_price)->order('is_show desc')->column('id');
郭盛 authored
433 434 435
            $data = Db::name('pic')
                ->whereIn('id',$ids)
                ->field('id,title,thumbnail')
郭盛 authored
436
                ->order('is_show desc')
郭盛 authored
437 438 439 440 441 442 443
                ->page($page,$pageNum)
                ->select();
            foreach ($data as &$v){
                $v['thumbnail'] = $rule.$v['thumbnail'];
            }
            $this->success('success',$data);
        }
郭盛 authored
444 445
    }
郭盛 authored
446 447 448 449 450 451
    /**
     * @ApiTitle    (图片列表)
     * @ApiSummary  (图片列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/pic)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
郭盛 authored
452
     *
郭盛 authored
453
     * @ApiParams   (name="pictype_id", type="inter", required=false, description="类型ID")
郭盛 authored
454 455
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
郭盛 authored
456
     * @ApiReturn({
郭盛 authored
457 458 459 460 461 462 463 464
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": 4,//图片id,
            "thumbnail": //缩略图,
        }
        })
郭盛 authored
465
 */
郭盛 authored
466 467 468
    public function pic()
    {
        $rule = config('verify.path');
郭盛 authored
469 470 471 472 473
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');
        $pictype_id = $this->request->post('pictype_id');
        if (empty($pictype_id)) {
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
郭盛 authored
474
        }else{
郭盛 authored
475 476
            $pictype_id = ','.$pictype_id.',';
            $where['pictype_ids'] = ['like',"%$pictype_id%"];
郭盛 authored
477
            $data = Db::name('pic')
郭盛 authored
478
                ->field('id,thumbnail,title')
郭盛 authored
479
                ->where($where)
郭盛 authored
480
                ->order('is_show desc')
郭盛 authored
481
                ->page($page, $pageNum)
郭盛 authored
482
                ->select();
郭盛 authored
483 484
            foreach ($data as &$v) {
                $v['thumbnail'] = $rule . $v['thumbnail'];
郭盛 authored
485
            }
郭盛 authored
486
            $this->success('SUCCESS', $data);
郭盛 authored
487 488
        }
    }
郭盛 authored
489
郭盛 authored
490
    /**
郭盛 authored
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
     * @ApiTitle    (分类下的图片视频)
     * @ApiSummary  (分类下的图片视频)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/pic_video)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="type_id", type="inter", required=true, description="地区ID")
     * @ApiParams   (name="type", type="inter", required=false, description="类型ID(图片为1 视频为2)")
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": 4,//图片id,
            "thumbnail": //缩略图,
        }
        })
     */
    public function pic_video()
    {
        $rule = config('verify.path');
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $type_id = $this->request->post('type_id');
        $type = $this->request->post('type');
        if($type == 1){
            $type = ','.$type_id.',';
            $where['type_ids'] = ['like',"%$type%"];
            $data = Db::name('pic')
                ->where($where)
                ->field('id,thumbnail,title')
524
                ->order('is_top desc,id desc')
郭盛 authored
525 526 527 528 529 530 531 532 533 534 535
                ->page($page,$pageNum)
                ->select();
            foreach ($data as &$v){
                $v['thumbnail'] = $rule.$v['thumbnail'];
            }
            $this->success('SUCCESS',$data);
        }else{
            $type = ','.$type_id.',';
            $where['type_ids'] = ['like',"%$type%"];
            $data = Db::name('video')
                ->where($where)
郭盛 authored
536
                ->field('id,thumbnail,video,title')
郭盛 authored
537
                ->order('is_show desc,id desc')
郭盛 authored
538 539 540 541 542 543 544 545 546 547 548 549
                ->page($page,$pageNum)
                ->select();
            foreach ($data as &$v){
                $v['thumbnail'] = $rule.$v['thumbnail'];
                $v['video'] = $rule.$v['video'];
            }
            $this->success('SUCCESS',$data);
        }

    }

    /**
郭盛 authored
550 551 552 553 554 555
     * @ApiTitle    (视频列表)
     * @ApiSummary  (视频列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/video)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="type_id", type="inter", required=false, description="地区ID")
郭盛 authored
556 557
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
郭盛 authored
558 559 560 561 562 563 564 565 566 567 568 569 570 571
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": //图片id,
            "thumbnail": //视频封面,
            "video"://视频地址
        }
        })
     */
    public function video()
    {
        $rule = config('verify.path');
郭盛 authored
572 573
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
郭盛 authored
574 575 576
        $type_id = $this->request->post('type_id');
        if(empty($type_id)){
            $data = Db::name('video')
郭盛 authored
577
                ->field('id,thumbnail,video,share')
郭盛 authored
578
                ->order('is_show desc')
郭盛 authored
579
                ->page($page,$pageNum)
郭盛 authored
580 581
                ->select();
            foreach ($data as &$v){
郭盛 authored
582
                $v['share'] = $rule.$v['share'];
郭盛 authored
583 584 585 586 587 588 589 590 591
                $v['thumbnail'] = $rule.$v['thumbnail'];
                $v['video'] = $rule.$v['video'];
            }
            $this->success('SUCCESS',$data);
        }else{
            $type = ','.$type_id.',';
            $where['type_ids'] = ['like',"%$type%"];
            $data = Db::name('video')
                ->where($where)
郭盛 authored
592
                ->field('id,thumbnail,video,share')
郭盛 authored
593
                ->order('is_show desc')
郭盛 authored
594
                ->page($page,$pageNum)
郭盛 authored
595 596
                ->select();
            foreach ($data as &$v){
郭盛 authored
597
                $v['share'] = $rule.$v['share'];
郭盛 authored
598 599 600 601 602 603 604
                $v['thumbnail'] = $rule.$v['thumbnail'];
                $v['video'] = $rule.$v['video'];
            }
            $this->success('SUCCESS',$data);
        }
    }
郭盛 authored
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
    /**
     * @ApiTitle    (精美大片列表)
     * @ApiSummary  (精美大片列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/won)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id": //图片id,
    "thumbnail": //视频封面,
    "video"://视频地址
    }
    })
     */
    public function won()
    {
        $rule = config('verify.path');
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
郭盛 authored
630
        $data = Db::name('wonderful')
郭盛 authored
631
            ->field('id,thumbnail,video,title,content,share')
郭盛 authored
632 633 634 635 636
            ->order('id desc')
            ->page($page,$pageNum)
            ->select();
        foreach ($data as &$v){
            $v['thumbnail'] = $rule.$v['thumbnail'];
郭盛 authored
637
            $v['share'] = $rule.$v['share'];
郭盛 authored
638
            $v['video'] = $rule.$v['video'];
郭盛 authored
639
        }
郭盛 authored
640
        $this->success('SUCCESS',$data);
郭盛 authored
641
郭盛 authored
642
    }
郭盛 authored
643
郭盛 authored
644
    /**
郭盛 authored
645 646 647 648 649 650 651 652 653 654 655 656 657
     * @ApiTitle    (图片详情)
     * @ApiSummary  (图片详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/picdetail)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="pic_id", type="inter", required=true, description="图片ID")
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": 4,//图片id,
郭盛 authored
658
            "title"://标题
郭盛 authored
659
            "thumbnail": //缩略图,
郭盛 authored
660
            "accredit": //授权书图片
郭盛 authored
661
            "water_url": //小样带水印的图片地址,
郭盛 authored
662 663 664 665 666 667 668 669 670 671 672 673
           "price"://正常价格,
           "vip_price"://vip价格,
           "content"://图片介绍,
           "is_vip"://是否为会员(0否 1是)

        }
    })
     */
    public function picdetail()
    {
        $uid = $this->uid;
        $rule = config('verify.path');
郭盛 authored
674
        $lu = config('verify.lu');
郭盛 authored
675 676 677 678 679 680 681 682 683
        $res = Db::name('user')
            ->where('id',$uid)
            ->field('id,is_vip')
            ->find();
        if($res['is_vip'] == 0){
            $pic_id = $this->request->post('pic_id');
            if(empty($pic_id)){
                $this->error(['code'=>2,'msg'=>'缺少必要参数']);
            }
郭盛 authored
684 685 686
            $accredit = Db::name('accredit')
                ->where('id',1)
                ->find();
郭盛 authored
687
            $data = Db::name('pic')
郭盛 authored
688
                ->field('text_ids,address_ids,id,keyword,title,thumbnail,price,url,code,click_num')
郭盛 authored
689 690
                ->where('id',$pic_id)
                ->find();
郭盛 authored
691 692 693
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'参数错误']);
            }
694 695 696 697 698 699 700 701 702 703
            $keyword = str_replace(' ',',',$data['keyword']);

            //单取出所有关键字合并数组
            $text_ids = explode(',',trim($data['text_ids'],','));
            $address_ids = explode(',',trim($data['address_ids'],','));
            $words = array_merge($text_ids,$address_ids);
            $keywords = Db::name('words')
                ->whereIn('id',$words)
                ->column('name');
            $keywords = implode(',',$keywords);
郭盛 authored
704 705 706 707 708
            if(empty($keywords)){
                $key = $keyword;
            }else{
                $key = $keyword.','.$keywords;
            }
709 710
            $a = trim($key,',');
            $data['keyword'] = explode(',',$a);
711 712 713 714 715 716
            array_push($data['keyword'],$data['price']);
            foreach ($data['keyword'] as $k=>$v){
                if(!$v){
                    unset($data['keyword'][$k]);
                }
            }
郭盛 authored
717
            $base_url = $data['thumbnail'];
郭盛 authored
718 719
            $click_num = $data['click_num'] + 1;
            Db::name('pic')->where('id',$pic_id)->update(['click_num'=>$click_num]);
郭盛 authored
720
            $data['accredit'] = $rule.$accredit['thumbnail'];
郭盛 authored
721
            $qiniu_url = $rule.$data['thumbnail'];
郭盛 authored
722
            $a = file_get_contents($qiniu_url);
郭盛 authored
723
            $path = './uploads/'.explode('/',$base_url)[2].'/';
郭盛 authored
724 725 726
            if(!file_exists($path)) {
                mkdir($path,0777,true);
            }
郭盛 authored
727
            file_put_contents('.'.$base_url,$a);
郭盛 authored
728
            $data['water_url'] = request()->domain().$data['thumbnail'];
郭盛 authored
729 730

郭盛 authored
731
            $data['vip_price'] = $data['price'] * 0.75;
郭盛 authored
732 733
            $data['thumbnail'] = $rule.$data['thumbnail'];
            $data['is_vip'] = 0;
郭盛 authored
734 735 736 737 738 739 740 741 742 743 744 745 746 747


            //我已经购买过的视频
            $video_buy = Db::name('iphone')
                ->where('user_id',$uid)
                ->where('status',2)
                ->column('pic_id');
            if(in_array($pic_id,$video_buy)){
                $data['is_buy'] = 1;
            }else{
                $data['is_buy'] = 2;
            }

郭盛 authored
748 749 750 751 752 753 754
            $this->success('SUCCESS',$data);
        }elseif($res['is_vip'] == 1){
            $pic_id = $this->request->post('pic_id');
            if(empty($pic_id)){
                $this->error(['code'=>2,'msg'=>'缺少必要参数']);
            }
            $data = Db::name('pic')
郭盛 authored
755
                ->field('text_ids,address_ids,keyword,id,title,thumbnail,price,url,code,click_num')
郭盛 authored
756 757
                ->where('id',$pic_id)
                ->find();
郭盛 authored
758 759 760
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'参数错误']);
            }
761 762 763 764 765 766 767 768 769 770
            $keyword = str_replace(' ',',',$data['keyword']);

            //单取出所有关键字合并数组
            $text_ids = explode(',',trim($data['text_ids'],','));
            $address_ids = explode(',',trim($data['address_ids'],','));
            $words = array_merge($text_ids,$address_ids);
            $keywords = Db::name('words')
                ->whereIn('id',$words)
                ->column('name');
            $keywords = implode(',',$keywords);
郭盛 authored
771 772 773 774 775
            if(empty($keywords)){
                $key = $keyword;
            }else{
                $key = $keyword.','.$keywords;
            }
776 777 778
            $a = trim($key,',');
            $data['keyword'] = explode(',',$a);
郭盛 authored
779 780 781
            $accredit = Db::name('accredit')
                ->where('id',1)
                ->find();
782 783 784 785 786 787
            array_push($data['keyword'],$data['price']);
            foreach ($data['keyword'] as $k=>$v){
                if(!$v){
                    unset($data['keyword'][$k]);
                }
            }
郭盛 authored
788
            $base_url = $data['thumbnail'];
郭盛 authored
789 790
            $click_num = $data['click_num'] + 1;
            Db::name('pic')->where('id',$pic_id)->update(['click_num'=>$click_num]);
郭盛 authored
791
            $data['is_vip'] = 1;
郭盛 authored
792
            $data['accredit'] = $rule.$accredit['thumbnail'];
郭盛 authored
793
            $qiniu_url = $rule.$data['thumbnail'];
郭盛 authored
794 795
            $a = file_get_contents($qiniu_url);
            $path = './uploads/'.explode('/',$base_url)[2].'/';
郭盛 authored
796
郭盛 authored
797 798 799 800
            if(!file_exists($path)){
                mkdir($path,0777,true);
            }
            file_put_contents('.'.$base_url,$a);
郭盛 authored
801
            $data['water_url'] = request()->domain().$data['thumbnail'];
郭盛 authored
802
            $data['vip_price'] = $data['price'] * 0.75;
郭盛 authored
803
            $data['thumbnail'] = $rule.$data['thumbnail'];
郭盛 authored
804 805 806 807 808 809 810 811 812 813
            //我已经购买过的视频
            $video_buy = Db::name('iphone')
                ->where('user_id',$uid)
                ->where('status',2)
                ->column('pic_id');
            if(in_array($pic_id,$video_buy)){
                $data['is_buy'] = 1;
            }else{
                $data['is_buy'] = 2;
            }
郭盛 authored
814 815 816 817
            $this->success('SUCCESS',$data);
        }
    }
郭盛 authored
818 819 820


郭盛 authored
821
    /**
郭盛 authored
822 823 824 825 826 827 828 829 830 831 832 833 834 835
     * @ApiTitle    (视频详情)
     * @ApiSummary  (视频详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/videodetail)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="video_id", type="inter", required=true, description="视频ID")
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": 4,//视频id,
            "title"://标题
836
            "keyword"://关键字
郭盛 authored
837
            "accredit": //授权书图片
郭盛 authored
838 839 840 841 842
            "thumbnail": //视频封面图,
            "video": //2K视频地址,
            "water_url"://小样视频网址
            "price"://2K价格,
            "vip_price"://2Kvip价格,
郭盛 authored
843 844 845 846
            "four_price"://4K价格,
            "four_vipprice"://4Kvip价格,
            "eight_price"://8K价格,
            "eight_vipprice"://8Kvip价格,
郭盛 authored
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
            "content"://图片介绍,
            "is_vip"://是否为会员(0否 1是)
        }
        })
     */
    public function videodetail()
    {
        $uid = $this->uid;
        $rule = config('verify.path');
        $res = Db::name('user')
            ->where('id',$uid)
            ->field('id,is_vip')
            ->find();
        if($res['is_vip'] == 0){
            $pic_id = $this->request->post('video_id');
            if(empty($pic_id)){
                $this->error(['code'=>2,'msg'=>'缺少必要参数']);
            }
            $data = Db::name('video')
866
                ->field('text_ids,address_ids,keyword,id,click_num,title,thumbnail,video,price,four_price,eight_price,water_url,two_url,four_url,two_code,four_code,eight_code,eight_url,content')
郭盛 authored
867 868
                ->where('id',$pic_id)
                ->find();
869
            $keyword = str_replace(' ',',',$data['keyword']);
郭盛 authored
870 871 872
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'参数错误']);
            }
873 874 875
            if(empty($data['eight_price'])){
                $data['eight_price'] = 0;
            }
876 877 878 879 880 881 882 883 884

            //单取出所有关键字合并数组
            $text_ids = explode(',',trim($data['text_ids'],','));
            $address_ids = explode(',',trim($data['address_ids'],','));
            $words = array_merge($text_ids,$address_ids);

            $keywords = Db::name('words')
                ->whereIn('id',$words)
                ->column('name');
郭盛 authored
885
886
            $keywords = implode(',',$keywords);
郭盛 authored
887
郭盛 authored
888
郭盛 authored
889 890 891 892 893
            if(empty($keywords)){
                $key = $keyword;
            }else{
                $key = $keyword.','.$keywords;
            }
894
            $data['keyword'] = explode(',',$key);
895 896 897 898 899 900
            array_push($data['keyword'],$data['price']);
            foreach ($data['keyword'] as $k=>$v){
                if(!$v){
                    unset($data['keyword'][$k]);
                }
            }
郭盛 authored
901 902 903
            $accredit = Db::name('accredit')
                ->where('id',1)
                ->find();
郭盛 authored
904 905
            $click_num = $data['click_num']+1;
            Db::name('video')->where('id',$pic_id)->update(['click_num'=>$click_num]);
郭盛 authored
906
            $data['vip_price'] = $data['price']*0.75;
郭盛 authored
907
            $data['accredit'] = $rule.$accredit['thumbnail'];
郭盛 authored
908 909
            $data['four_vipprice'] = $data['four_price']*0.75;
            $data['eight_vipprice'] = $data['eight_price']*0.75;
郭盛 authored
910 911 912
            $data['thumbnail'] = $rule.$data['thumbnail'];
            $data['video'] = $rule.$data['video'];
            $data['is_vip'] = 0;
郭盛 authored
913 914 915 916 917 918
            $data['content'] = explode(',',trim($data['content'],' '));
            foreach ($data['content'] as $k=>$v){
                if(!$v){
                    unset($data['content'][$k]);
                }
            }
郭盛 authored
919
            $this->success('SUCCESS',$data);
郭盛 authored
920
        }elseif($res['is_vip'] == 1){
郭盛 authored
921
            $pic_id = $this->request->post('video_id');
郭盛 authored
922 923 924 925
            if(empty($pic_id)){
                $this->error(['code'=>2,'msg'=>'缺少必要参数']);
            }
            $data = Db::name('video')
926
                ->field('text_ids,address_ids,keyword,id,click_num,title,thumbnail,video,price,four_price,eight_price,water_url,two_url,two_code,four_code,eight_code,four_url,eight_url,content')
郭盛 authored
927 928
                ->where('id',$pic_id)
                ->find();
929
            $keyword = str_replace(' ',',',$data['keyword']);
郭盛 authored
930 931 932
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'参数错误']);
            }
933 934 935 936 937 938 939 940 941 942 943 944
            if(empty($data['eight_price'])){
                $data['eight_price'] = 0;
            }
            //单取出所有关键字合并数组
            $text_ids = explode(',',trim($data['text_ids'],','));
            $address_ids = explode(',',trim($data['address_ids'],','));
            $words = array_merge($text_ids,$address_ids);

            $keywords = Db::name('words')
                ->whereIn('id',$words)
                ->column('name');
            $keywords = implode(',',$keywords);
郭盛 authored
945 946 947 948 949
            if(empty($keywords)){
                $key = $keyword;
            }else{
                $key = $keyword.','.$keywords;
            }
950
            $data['keyword'] = explode(',',$key);
951 952 953 954 955 956
            array_push($data['keyword'],$data['price']);
            foreach ($data['keyword'] as $k=>$v){
                if(!$v){
                    unset($data['keyword'][$k]);
                }
            }
郭盛 authored
957 958 959
            $accredit = Db::name('accredit')
                ->where('id',1)
                ->find();
郭盛 authored
960 961
            $click_num = $data['click_num']+1;
            Db::name('video')->where('id',$pic_id)->update(['click_num'=>$click_num]);
郭盛 authored
962
            $data['is_vip'] = 1;
郭盛 authored
963
            $data['accredit'] = $rule.$accredit['thumbnail'];
郭盛 authored
964 965 966
            $data['vip_price'] = $data['price']*0.75;
            $data['four_vipprice'] = $data['four_price']*0.75;
            $data['eight_vipprice'] = $data['eight_price']*0.75;
郭盛 authored
967 968
            $data['thumbnail'] = $rule.$data['thumbnail'];
            $data['video'] = $rule.$data['video'];
郭盛 authored
969 970 971 972 973 974
            $data['content'] = explode(',',trim($data['content'],' '));
            foreach ($data['content'] as $k=>$v){
                if(!$v){
                    unset($data['content'][$k]);
                }
            }
郭盛 authored
975 976 977 978 979 980 981 982
            $this->success('SUCCESS',$data);
        }
    }

    /**
     * @ApiTitle    (是否购买过)
     * @ApiSummary  (是否购买过)
     * @ApiMethod   (POST)
郭盛 authored
983
     * @ApiRoute    (/api/user/is_buy)
郭盛 authored
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="video_id", type="inter", required=true, description="视频ID")
     * @ApiParams   (name="attr", type="inter", required=true, description="视频属性")
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
        "is_buy"://是否购买过1购买过2没有
    }
    })
     */
    public function is_buy()
    {
        $user_id = $this->uid;
郭盛 authored
1001
        $video['id'] = $this->request->param('video_id');
郭盛 authored
1002 1003
        $video['attr'] = $this->request->param('attr');
郭盛 authored
1004
        $a = serialize($video);
郭盛 authored
1005
郭盛 authored
1006 1007 1008 1009
        //我已经购买过的视频
        $video_buy = Db::name('iphone')
            ->where('user_id',$user_id)
            ->where('status',2)
郭盛 authored
1010 1011 1012 1013 1014 1015
            ->where('video_id',$a)
            ->find();
        if(empty($video_buy)){
            $data['is_buy'] = 2;
        }else{
            $data['is_buy'] = 1;
郭盛 authored
1016
        }
郭盛 authored
1017
        $this->success('SUCCESS',$data);
郭盛 authored
1018 1019 1020
    }

    /**
1021 1022
     * @ApiTitle    (搜索关键词内容)
     * @ApiSummary  (搜索关键词内容)
郭盛 authored
1023
     * @ApiMethod   (POST)
1024
     * @ApiRoute    (/api/user/words)
郭盛 authored
1025 1026 1027 1028 1029 1030 1031
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
1032 1033
        "id"://记录id,
        "name"://关键字名称
郭盛 authored
1034 1035 1036
    }
    })
     */
1037
    public function words()
郭盛 authored
1038
    {
1039 1040 1041 1042 1043 1044 1045 1046 1047
        $data['address'] = Db::name('words')
            ->where('type',1)
            ->field('id,name')
            ->select();
        $data['text'] = Db::name('words')
            ->where('type',2)
            ->field('id,name')
            ->select();
        $data['price'] = [
郭盛 authored
1048 1049 1050
          '0'=>'800',
          '1'=>'1200',
          '2'=>'1800',
1051 1052
        ];
        $this->success('success',$data);
郭盛 authored
1053 1054
    }
1055 1056 1057 1058 1059 1060 1061
    /**
     * @ApiTitle    (通过详情页关键词搜索)
     * @ApiSummary  (通过详情页关键词搜索)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/search_key)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
郭盛 authored
1062
     * @ApiHeaders  (name=type, type=string, required=true, description="类型(视频1图片2)")
1063
     * @ApiParams   (name="keyword", type=string, required=true, description="关键字")
郭盛 authored
1064 1065
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
     *
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id": //id,
            "thumbnail": //视频封面,
            "title"://视频标题
        }
        })
     */
    public function search_key()
    {
        $user_id = $this->uid;
        $rule = config('verify.path');
郭盛 authored
1083 1084
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
1085
        $keyword = $this->request->param('keyword');
郭盛 authored
1086 1087
        $type = $this->request->param('type');
        if(empty($type) || empty($keyword)){
1088 1089
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
郭盛 authored
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
        if($type == 1){
            //查出所有手动写入该关键词的素材ID
            $hand_ids = Db::name('video')
                ->where('keyword','like',"%$keyword%")
                ->column('id');
            //根据用户点选的关键词搜索对应的关键词表找出该关键词是否存在,如果存在找出ID,继续查素材含有该ID的素材ID
            $words_id = Db::name('words')
                ->where('name',$keyword)
                ->find();
            if(empty($words_id)){
                $words_ids = [];
            }else{
                if($words_id['type'] == 1){
                    $address_id = ','.$words_id['id'].',';
                    $words_ids = Db::name('video')
                        ->where('address_ids','like',"%$address_id%")
                        ->column('id');
                }
                if($words_id['type'] == 2){
                    $text_id = ','.$words_id['id'].',';
                    $words_ids = Db::name('video')
                        ->where('text_ids','like',"%$text_id%")
                        ->column('id');
                }
1114
            }
郭盛 authored
1115 1116 1117 1118 1119 1120 1121 1122 1123
            //合并所有查出的数组ID
            $public_ids = array_merge($hand_ids,$words_ids);
            $data = Db::name('video')
                ->whereIn('id',$public_ids)
                ->field('id,title,thumbnail')
                ->page($page,$pageNum)
                ->select();
            foreach ($data as &$v){
                $v['thumbnail'] = $rule.$v['thumbnail'];
1124
            }
郭盛 authored
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
            $this->success('SUCCESS',$data);
        }elseif ($type == 2){
            //查出所有手动写入该关键词的素材ID
            $hand_ids = Db::name('pic')
                ->where('keyword','like',"%$keyword%")
                ->column('id');
            //根据用户点选的关键词搜索对应的关键词表找出该关键词是否存在,如果存在找出ID,继续查素材含有该ID的素材ID
            $words_id = Db::name('words')
                ->where('name',$keyword)
                ->find();
            if(empty($words_id)){
                $words_ids = [];
            }else{
                if($words_id['type'] == 1){
                    $address_id = ','.$words_id['id'].',';
                    $words_ids = Db::name('pic')
                        ->where('address_ids','like',"%$address_id%")
                        ->column('id');
                }
                if($words_id['type'] == 2){
                    $text_id = ','.$words_id['id'].',';
                    $words_ids = Db::name('pic')
                        ->where('text_ids','like',"%$text_id%")
                        ->column('id');
                }
            }
            //合并所有查出的数组ID
            $public_ids = array_merge($hand_ids,$words_ids);
            $data = Db::name('pic')
                ->whereIn('id',$public_ids)
                ->field('id,title,thumbnail')
                ->page($page,$pageNum)
                ->select();
            foreach ($data as &$v){
                $v['thumbnail'] = $rule.$v['thumbnail'];
            }
            $this->success('SUCCESS',$data);
        }else{
            $this->error('参数错误');
1164 1165 1166
        }
    }
郭盛 authored
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
    /**
     * @ApiTitle    (我的)
     * @ApiSummary  (我的)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/mine)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id":       //用户ID
            "nickname": //昵称,
            "avatar":   //头像,
            "money" :   //余额
            "is_vip":   //是否为会员(0否 1是)
        }
        })
     */
    public function mine()
    {
        $user_id = $this->uid;
        $data = Db::name('user')
            ->where('id',$user_id)
            ->field('id,nickname,avatar,money,is_vip')
            ->find();
        $this->success('SUCCESS',$data);
    }

    /**
     * @ApiTitle    (创建充值订单)
     * @ApiSummary  (创建充值订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/toporder)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="money", type="float", required=true, description="充值金额")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "order_id"://订单ID
        }
        })
     */
    public function toporder()
    {
        $param['user_id'] = $this->uid;
郭盛 authored
1218
        $param['money'] = $this->request->post('money');
郭盛 authored
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
        if(empty( $param['money'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }elseif ( $param['money']<=0){
            $this->error(['code'=>3,'msg'=>'非法操作']);
        }else{
            $param['createtime'] = time();
            $param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $data = Db::name('toporder')
                ->insertGetId($param);
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'sql执行失败']);
            }
            $this->success('SUCCESS',['order_id'=>$data]);
        }

    }
郭盛 authored
1236
    /**
郭盛 authored
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
     * @ApiTitle    (创建开通会员订单)
     * @ApiSummary  (创建开通会员订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/viporder)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="total", type="float", required=true, description="金额")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "order_id"://订单ID
        }
        })
     */
    public function viporder()
    {
        $param['user_id'] = $this->uid;
郭盛 authored
1257 1258 1259 1260 1261
        if($param['user_id'] == 12){
            $param['total'] = 8000;
        }else{
            $param['total'] = $this->request->post('total');
        }
郭盛 authored
1262 1263
        if(empty( $param['total'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
郭盛 authored
1264
        }elseif ($param['total']<8000){
郭盛 authored
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
            $this->error(['code'=>3,'msg'=>'开通会员至少需要8000元哦']);
        }else{
            $param['createtime'] = time();
            $param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $data = Db::name('viporder')
                ->insertGetId($param);
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'sql执行失败']);
            }
            $this->success('SUCCESS',['order_id'=>$data]);
        }

    }

    /**
郭盛 authored
1280 1281
     * @ApiTitle    (会员介绍)
     * @ApiSummary  (会员介绍)
郭盛 authored
1282 1283 1284 1285 1286 1287 1288 1289 1290
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/vipdesc)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
郭盛 authored
1291
        "content":       //会员介绍内容
郭盛 authored
1292 1293 1294 1295 1296
    }
    })
     */
    public function vipdesc()
    {
郭盛 authored
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
        $data = Db::name('vip')
            ->field('content')
            ->where('id',2)
            ->find();
        $this->success('SUCCESS',$data);
    }

    /**
     * @ApiTitle    (会员须知)
     * @ApiSummary  (会员须知)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/vipdetail)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "text":       //会员须知内容
    }
    })
     */
    public function vipdetail()
    {
        $data = Db::name('vip')
郭盛 authored
1323
            ->field('desc')
郭盛 authored
1324 1325
            ->where('id',2)
            ->find();
郭盛 authored
1326
郭盛 authored
1327 1328 1329
        $this->success('SUCCESS',$data);
    }
郭盛 authored
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
    /**
     * @ApiTitle    (购物车列表)
     * @ApiSummary  (购物车列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/car)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
        "id"://购物车ID
          "user_id"://用户ID
          "pic_id"://图片的ID
          "video_id"://视频的ID
          "pic":[
                "id"://图片ID
               "title"://图片标题
               "thumbnail"://缩略图
               "url"://高清百度云盘地址
               "price"://普通价格
               "vip_price"://vip价格
          ],
          "video":[
               "id"://视频ID
               "title"://视频标题
               "thumbnail"://视频封面图片
               "video"://视频地址
               "two_url"://2K视频云盘地址
               "four_url"://4k视频云盘地址
               "eight_url"://8k视频云盘地址
               "price"://2k视频原价格
               "four_price"://4k视频原价格
               "eight_price"://8k视频原价格
               "vip_price"://2k会员价格
               "four_vipprice"://4k会员价格
               "eight_vipprice"://8k会员价格
          ]
    }
    })
     */
    public function car()
    {
        $user_id = $this->uid;
郭盛 authored
1375
        $rule = config('verify.path');
郭盛 authored
1376 1377 1378 1379 1380 1381 1382
        //查询该用户是否为会员
        $res = Db::name('user')
            ->where('id',$user_id)
            ->field('id,is_vip')
            ->find();
        //判断
        if($res['is_vip'] == 0){
郭盛 authored
1383
            //不是会员的情况
郭盛 authored
1384 1385 1386
            $data = Db::name('car')
                ->where('user_id',$user_id)
                ->field('id,user_id,pic_id,video_id')
郭盛 authored
1387
                ->order('createtime desc,id desc')
郭盛 authored
1388
                ->select();
郭盛 authored
1389 1390 1391 1392
            foreach ($data as &$v) {
                if(!empty($v['pic_id'])){
                    $v['pic_id'] = Db::name('pic')->field('id,title,thumbnail,url,price')->where('id',$v['pic_id'])->find();
                    $v['pic_id']['thumbnail'] = $rule.$v['pic_id']['thumbnail'];
郭盛 authored
1393
                }
郭盛 authored
1394 1395 1396 1397
                if(!empty($v['video_id'])){
                    $v['video_id'] = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v['video_id'])->find();
                    $v['video_id']['thumbnail'] = $rule.$v['video_id']['thumbnail'];
                    $v['video_id']['video'] = $rule.$v['video_id']['video'];
郭盛 authored
1398
                }
郭盛 authored
1399 1400 1401 1402 1403 1404 1405
            }
            $this->success('SUCCESS',$data);
        }else{
            //是的情况
            $data = Db::name('car')
                ->where('user_id',$user_id)
                ->field('id,user_id,pic_id,video_id')
郭盛 authored
1406
                ->order('createtime desc,id desc')
郭盛 authored
1407 1408
                ->select();
            foreach ($data as &$v){
郭盛 authored
1409 1410 1411 1412
                if(!empty($v['pic_id'])){
                    $v['pic_id'] = Db::name('pic')->field('id,title,thumbnail,url,price')->where('id',$v['pic_id'])->find();
                    $v['pic_id']['thumbnail'] = $rule.$v['pic_id']['thumbnail'];
                    $v['pic_id']['vipprice'] = $v['pic_id']['price']*0.75;
郭盛 authored
1413
                }
郭盛 authored
1414 1415 1416 1417 1418 1419 1420
                if(!empty($v['video_id'])){
                    $v['video_id'] = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v['video_id'])->find();
                    $v['video_id']['thumbnail'] = $rule.$v['video_id']['thumbnail'];
                    $v['video_id']['video'] = $rule.$v['video_id']['video'];
                    $v['video_id']['vipprice'] = $v['video_id']['price'] * 0.75;
                    $v['video_id']['four_vipprice'] = $v['video_id']['four_price'] * 0.75;
                    $v['video_id']['eight_vipprice'] = $v['video_id']['eight_price'] * 0.75;
郭盛 authored
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
                }
            }
            $this->success('SUCCESS',$data);
        }
    }

    /**
     * @ApiTitle    (加入购物车)
     * @ApiSummary  (加入购物车)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/addcar)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="pic_id", type="inter", required=false, description="图片ID")
     * @ApiParams   (name="video_id", type="inter", required=false, description="视频ID")
郭盛 authored
1436
     *
郭盛 authored
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    })
     */
    public function addcar()
    {
        $user_id = $this->uid;
        $pic_id = $this->request->param('pic_id');
        $video_id = $this->request->param('video_id');
郭盛 authored
1449 1450 1451
        if(empty($pic_id) && empty($video_id)){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
郭盛 authored
1452
        if(empty($pic_id)){
郭盛 authored
1453
            //接受视频ID并判断
1454 1455 1456 1457 1458 1459 1460 1461
            $data = Db::name('car')
                ->field('id')
                ->where('user_id',$user_id)
                ->where('video_id',$video_id)
                ->find();
            if(!empty($data)){
                $this->error(['code'=>2,'msg'=>'您已经添加过了']);
            }
郭盛 authored
1462
            $param['video_id'] = $video_id;
郭盛 authored
1463
            $param['createtime'] = time();
郭盛 authored
1464
            $param['user_id'] = $user_id;
郭盛 authored
1465 1466 1467 1468 1469
            $data = Db::name('car')
                ->insertGetId($param);
            if($data){
                $this->success('SUCCESS');
            }else{
郭盛 authored
1470
                $this->error(['code'=>3,'msg'=>'加入购物车失败']);
郭盛 authored
1471
            }
郭盛 authored
1472
        }elseif (empty($video_id)){
1473 1474 1475
            $data = Db::name('car')
                ->field('id')
                ->where('user_id',$user_id)
郭盛 authored
1476
                ->where('pic_id',$pic_id)
1477 1478 1479 1480
                ->find();
            if(!empty($data)){
                $this->error(['code'=>2,'msg'=>'您已经添加过了']);
            }
郭盛 authored
1481
            $param['pic_id'] = $pic_id;
郭盛 authored
1482 1483
            $param['createtime'] = time();
            $param['user_id'] = $user_id;
郭盛 authored
1484
            $data = Db::name('car')
郭盛 authored
1485
                ->insertGetId($param);
郭盛 authored
1486 1487 1488
            if($data){
                $this->success('SUCCESS');
            }else{
郭盛 authored
1489
                $this->error(['code'=>3,'msg'=>'加入购物车失败']);
郭盛 authored
1490
            }
郭盛 authored
1491 1492
        }else{
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
郭盛 authored
1493 1494 1495
        }
    }
郭盛 authored
1496
    /**
郭盛 authored
1497
     * @ApiTitle    (删除购物车商品)
郭盛 authored
1498
     * @ApiSummary  (删除购物车商品)
郭盛 authored
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/delcar)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="ids[]", type="inter", required=true, description="购物车ID")
     *
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    })
     */
    public function delcar()
    {
        $user_id = $this->uid;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
        $data = Db::name('car')
            ->where('user_id',$user_id)
            ->whereIn('id',$ids)
            ->delete();
        if($data){
            $this->success('SUCCESS','删除成功');
        }else{
            $this->error(['code'=>2,'msg'=>'sql运行失败']);
        }


    }

    /**
郭盛 authored
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
     * @ApiTitle    (创建图片订单)
     * @ApiSummary  (创建图片订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/picorder)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="pic_id", type="inter", required=true, description="图片ID")
     * @ApiParams   (name="total", type="float", required=true, description="价格")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
        "order_id"://订单ID
    }
    })
     */
    public function picorder()
    {
        $param['user_id'] = $this->uid;
        $param['pic_id'] = $this->request->post('pic_id');
        if(empty($param['pic_id'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
        $param['total'] = $this->request->post('total');
        if(empty( $param['total'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }elseif ( $param['total']<=0){
            $this->error(['code'=>3,'msg'=>'非法操作']);
        }else{
郭盛 authored
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575
            $where['status'] = 2;
            $where['user_id'] = $param['user_id'];
            $arr = Db::name('order')
                ->field('id,pic_id')
                ->where($where)
                ->select();
            foreach ($arr as &$v){
                $v['pic_id'] = explode(',',$v['pic_id']);
                if(in_array($param['pic_id'],$v['pic_id'])){
                    $this->error(['code'=>2,'msg'=>'该图片已经购买过了']);
                }
            }
郭盛 authored
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
            $param['createtime'] = time();
            $param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $data = Db::name('order')
                ->insertGetId($param);
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'sql执行失败']);
            }
            $this->success('SUCCESS',['order_id'=>$data]);
        }
    }

    /**
     * @ApiTitle    (创建视频订单)
     * @ApiSummary  (创建视频订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/v_order)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="video_id", type="inter", required=true, description="视频ID")
郭盛 authored
1595
     * @ApiParams   (name="video_attr", type="inter", required=true, description="视频品质属性")
郭盛 authored
1596 1597 1598
     * @ApiParams   (name="total", type="float", required=true, description="价格")
     *
     * @ApiReturn({
郭盛 authored
1599 1600 1601 1602 1603 1604 1605
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "order_id"://订单ID
        }
        })
郭盛 authored
1606 1607 1608 1609
     */
    public function v_order()
    {
        $param['user_id'] = $this->uid;
郭盛 authored
1610 1611 1612 1613 1614 1615 1616 1617
        //接受视频ID并判断
        $video_id = $this->request->post('video_id');
        if(empty($video_id)){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
        //接受视频品质属性并判断
        $video_attr = $this->request->post('video_attr');
        if(empty($video_attr)){
郭盛 authored
1618 1619
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
郭盛 authored
1620
        //接受视频价格并判断
郭盛 authored
1621 1622 1623 1624 1625 1626
        $param['total'] = $this->request->post('total');
        if(empty( $param['total'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }elseif ( $param['total']<=0){
            $this->error(['code'=>3,'msg'=>'非法操作']);
        }else{
郭盛 authored
1627
            $a = [];
郭盛 authored
1628 1629
            $a[0]['id'] = $video_id;
            $a[0]['attr'] = $video_attr;
郭盛 authored
1630 1631
            $where['user_id'] = ['eq',$param['user_id']];
            $where['status'] = ['eq',2];
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641

            $res = Db::name('order')
                ->field('video_id')
                ->where($where)
                ->select();
            foreach ($res as &$v){
                $v['video_id'] = unserialize($v['video_id']);
                if(!empty($v['video_id'])){
                    foreach ($v['video_id'] as $v1){
                        if($v1['id'] == $video_id && $v1['attr'] == $video_attr){
郭盛 authored
1642
                            $this->error(['code'=>2,'msg'=>'该属性的视频已经购买过了','video_id'=>$v1['id'],'attr'=>$v1['attr']]);
1643 1644 1645
                        }
                    }
                }
郭盛 authored
1646
            }
郭盛 authored
1647
            $param['video_id'] = serialize($a);
郭盛 authored
1648 1649
            $param['createtime'] = time();
            $param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
郭盛 authored
1650
            $data = Db::name('order')
郭盛 authored
1651 1652 1653 1654
                ->insertGetId($param);
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'sql执行失败']);
            }
郭盛 authored
1655
            $this->success('SUCCESS',['order_id'=>$data,'video_id'=>$video_id,'attr'=>$video_attr]);
郭盛 authored
1656 1657 1658
        }
    }
郭盛 authored
1659
    /**
郭盛 authored
1660 1661 1662 1663 1664 1665
     * @ApiTitle    (创建组合订单)
     * @ApiSummary  (创建组合订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/orders)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
郭盛 authored
1666 1667
     * @ApiParams   (name="video_id", type="string", required=true, description="视频ID(多个以逗号隔开)")
     * @ApiParams   (name="video_attr", type="string", required=true, description="视频品质属性(多个以逗号隔开)")
郭盛 authored
1668
     * @ApiParams   (name="pic_id", type="string", required=true, description="图片ID")
郭盛 authored
1669
     * @ApiParams   (name="total", type="float", required=true, description="总价格")
郭盛 authored
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "order_id"://订单ID
        }
        })
     */
    public function orders()
    {
        $param['user_id'] = $this->uid;
郭盛 authored
1683
郭盛 authored
1684 1685 1686 1687 1688
        //接收视频ID加视频属性
        $video_ids = $this->request->post('video_id');
        $video_attrs = $this->request->post('video_attr');
        $video_id = explode(',',$video_ids);
        $video_attr = explode(',',$video_attrs);
郭盛 authored
1689
        $key = ['id','attr'];
郭盛 authored
1690 1691 1692

        //接收图片的ID
        $pic_id = explode(',',$this->request->post('pic_id'));
郭盛 authored
1693 1694 1695 1696

        $where['user_id'] = ['eq',$param['user_id']];
        $where['status'] = ['eq',2];
郭盛 authored
1697
        if(!empty($video_ids) && !empty($video_attrs)){
郭盛 authored
1698
            $a = $this->array_merge_more($key,$video_id,$video_attr);
郭盛 authored
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
            //查询视频ID
            $res = Db::name('order')
                ->field('video_id')
                ->where($where)
                ->select();
            foreach ($res as &$v){
                $v['video_id'] = unserialize($v['video_id']);
                if(!empty($v['video_id']) && !empty($a)){
                    foreach ($v['video_id'] as $v1){
                        foreach ($a as &$v2){
                            if($v1['id'] == $v2['id'] && $v1['attr'] == $v2['attr']){
                                $this->error(['code'=>2,'msg'=>'该属性的视频已经购买过了','video_id'=>$v2['id']]);
                            }
郭盛 authored
1712 1713 1714
                        }
                    }
                }
郭盛 authored
1715
            }
郭盛 authored
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
            $param['video_id'] = serialize($a);
        }else{
            //查询图片ID
            $arr = Db::name('order')
                ->field('pic_id')
                ->where($where)
                ->select();
            foreach ($arr as &$v){
                $v['pic_id'] = explode(',',$v['pic_id']);
                if(!empty($v['pic_id'])){
                    foreach ($pic_id as $v3){
                        if(in_array($v3,$v['pic_id'])){
                            $this->error(['code'=>2,'msg'=>'该图片已经购买过了','pic_id'=>$v3]);
                        }
郭盛 authored
1730 1731 1732 1733
                    }
                }
            }
        }
郭盛 authored
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
        $param['pic_id'] = $this->request->post('pic_id');
        $param['total'] = $this->request->post('total');
        if(empty( $param['total'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }elseif ( $param['total']<=0){
            $this->error(['code'=>3,'msg'=>'非法操作']);
        }else{
            $param['createtime'] = time();
            $param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $data = Db::name('order')
                ->insertGetId($param);
            if(empty($data)){
                $this->error(['code'=>2,'msg'=>'sql执行失败']);
            }
            $this->success('SUCCESS',['order_id'=>$data]);
        }
    }
郭盛 authored
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769

    /**
     * @ApiTitle    (创建苹果订单)
     * @ApiSummary  (创建苹果订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/iphone_order)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="video_id", type="string", required=true, description="视频ID")
     * @ApiParams   (name="video_attr", type="string", required=true, description="视频品质属性")
     * @ApiParams   (name="pic_id", type="string", required=true, description="图片ID")
     * @ApiParams   (name="total", type="float", required=true, description="总价格")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
郭盛 authored
1770 1771
    "is_vip"://是否是会员1是0否
    "is_enough"://余额是否充足1充足2不足
郭盛 authored
1772 1773 1774 1775 1776 1777 1778
    "order_id"://订单ID
    }
    })
     */
    public function iphone_order()
    {
        $param['user_id'] = $this->uid;
郭盛 authored
1779
        $user = Db::name('user')->where('id',$param['user_id'])->field('mobile,id,type,is_vip,money,mobile')->find();
郭盛 authored
1780 1781 1782
        if($user['type'] == 0){
            $this->error('该功能只支持苹果用户');
        }
郭盛 authored
1783
郭盛 authored
1784 1785 1786
        //查看用户是否是vip
        $data['is_vip'] = $user['is_vip'];
郭盛 authored
1787 1788 1789
        //接收视频ID加视频属性
        $video['id'] = $this->request->post('video_id');
        $video['attr'] = $this->request->post('video_attr');
郭盛 authored
1790 1791 1792 1793 1794
        if(!empty($video['id'])){
            if(empty($video['attr'])){
                $this->error('请选择视频属性');
            }
        }
郭盛 authored
1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806

        //接收图片的ID
        $pic_id = $this->request->param('pic_id');

        //价格
        $param['total'] = $this->request->post('total');
        if(empty( $param['total'])){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }elseif ( $param['total']<=0){
            $this->error(['code'=>3,'msg'=>'非法操作']);
        }
郭盛 authored
1807 1808 1809
        //查询用户余额是否充足
        if($user['money'] <  $param['total']){
            $data['is_enough'] = 2;
郭盛 authored
1810 1811 1812 1813

            //发送短信,通知客户
            $mobile = 13780608990;
            $mobile1 = 15588311507;
郭盛 authored
1814
            $content = "【仁甲看见SHOP】提醒您,您有新的苹果客户,客户电话为:$user[mobile] ,请您及时回复!";
郭盛 authored
1815 1816 1817 1818 1819 1820
            //发送短信
            $send = new Pay();
            $send->sms($mobile,$content);
            $send->sms($mobile1,$content);

郭盛 authored
1821
            $this->error('error',$data);
郭盛 authored
1822
郭盛 authored
1823
        }else{
郭盛 authored
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
            $data['is_enough'] = 1;

            $where['user_id'] = ['eq',$param['user_id']];
            $where['status'] = ['eq',2];
            if(!empty($video['id']) && !empty($video['attr'])){
                $video_s = serialize($video);
                //查看该图片或者该视频属性是否已经购买过
                $res = Db::name('iphone')
                    ->where($where)
                    ->where('video_id',$video_s)
                    ->find();
                if(!empty($res)){
                    $this->error(['code'=>2,'msg'=>'该属性的视频已经购买过了']);
                }
                $param['video_id'] = serialize($video);
            }else{
                //查询图片ID
                $arr = Db::name('iphone')
                    ->field('pic_id')
                    ->where($where)
                    ->select();
                foreach ($arr as &$v){
                    if(!empty($v['pic_id'])){
                        if($v['pic_id'] == $pic_id){
                            $this->error(['code'=>2,'msg'=>'该图片已经购买过了','pic_id'=>$pic_id]);
                        }
郭盛 authored
1850 1851
                    }
                }
郭盛 authored
1852
                $param['pic_id'] = $pic_id;
郭盛 authored
1853
            }
郭盛 authored
1854 1855 1856 1857 1858 1859 1860 1861
            $param['createtime'] = time();
            $param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $data_order = Db::name('iphone')
                ->insertGetId($param);
            if(empty($data_order)){
                $this->error(['code'=>2,'msg'=>'sql执行失败']);
            }else{
                $send = new Pay();
郭盛 authored
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894
                Db::startTrans();
                try{
                    //修改用户余额以及订单状态   同时给用户发送短信
                    $update = $user['money'] - $param['total'];
                    Db::name('user')->where('id',$param['user_id'])->update(['money'=>$update]);
                    Db::name('iphone')->where('id',$data_order)->update(['status'=>2]);
                    //查询订单数据
                    $order_info = Db::name('iphone')->where('id',$data_order)->find();
                    //用户购买的什么素材
                    if(empty($order_info['video_id'])){
                        $pic = Db::name('pic')->where('id',$order_info['pic_id'])->find();

                        //发送短信,通知客户
                        $mobile = $user['mobile'];
                        $content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。图片标题:$pic[title],云盘地址:$pic[url]";
                        //发送短信

                        $send->sms($mobile,$content);

                    }elseif (empty($order_info['pic_id'])){
                        $video_id = unserialize($order_info['video_id']);
                        $video = Db::name('video')->where('id',$video_id['id'])->find();
                        //发送短信,通知客户
                        $mobile = $user['mobile'];
                        if($video_id['attr'] == 1){
                            $content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。视频标题:$video[title],云盘地址:$video[two_url]";
                        }elseif ($video_id['attr'] == 2){
                            $content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。视频标题:$video[title],云盘地址:$video[four_url]";
                        }elseif ($video_id['attr'] == 3){
                            $content = "【仁甲看见SHOP】,感谢您购买仁甲看见SHOP素材。视频标题:$video[title],云盘地址:$video[eight_url]";
                        }
                        //发送短信
                        $send->sms($mobile,$content);
郭盛 authored
1895
                    }
郭盛 authored
1896
                    Db::commit();
郭盛 authored
1897
                    $this->success('success');
郭盛 authored
1898 1899 1900 1901
                } catch (\Exception $e) {
                    // 回滚事务
                    Db::rollback();
                    $this->error('error');
郭盛 authored
1902 1903 1904
                }
            }
郭盛 authored
1905
        }
郭盛 authored
1906
郭盛 authored
1907
郭盛 authored
1908 1909
    }
郭盛 authored
1910
郭盛 authored
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931
    /**
     * @ApiTitle    (发短信)
     * @ApiSummary  (发短信)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/duan_send)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    }
    })
     */
    public function duan_send(){
        $user_id = $this->uid;
        $user = Db::name('user')->where('id',$user_id)->value('mobile');

        //发送短信,通知客户
郭盛 authored
1932 1933
        $mobile = 13780608990;
        $mobile1 = 15588311507;
郭盛 authored
1934 1935 1936 1937 1938 1939 1940
        $content = "【仁甲看见SHOP】提醒您,您有新苹果客户要加入仁甲会大家庭,客户电话为:$user ,请您及时回复!";
        //发送短信
        $send = new Pay();
        $send->sms($mobile,$content);
        $send->sms($mobile1,$content);
    }
郭盛 authored
1941 1942 1943


郭盛 authored
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
    //将多个一维数组转为二维数组
    public function array_merge_more($keys, ...$arrs){
        // 检查参数是否正确
        if(!$keys || !is_array($keys) || !$arrs || !is_array($arrs) || count($keys)!=count($arrs)){
            return array();
        }
        // 一维数组中最大长度
        $max_len = 0;
        // 整理数据,把所有一维数组转重新索引
        for($i=0,$len=count($arrs); $i<$len; $i++){
            $arrs[$i] = array_values($arrs[$i]);

            if(count($arrs[$i])>$max_len){
                $max_len = count($arrs[$i]);
            }
        }
        // 合拼数据
        $result = array();
        for($i=0; $i<$max_len; $i++){
            $tmp = array();
            foreach($keys as $k=>$v){
                if(isset($arrs[$k][$i])){
                    $tmp[$v] = $arrs[$k][$i];
                }
            }
            $result[] = $tmp;
        }
        return $result;
    }
郭盛 authored
1974
    /**
郭盛 authored
1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
     * @ApiTitle    (删除订单)
     * @ApiSummary  (删除订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/delorder)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="ids[]", type="inter", required=true, description="订单ID")
     *
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
    })
     */
    public function delorder()
    {
        $user_id = $this->uid;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
        $data = Db::name('order')
            ->where('user_id',$user_id)
            ->whereIn('id',$ids)
            ->delete();
        if($data){
            $this->success('SUCCESS','删除成功');
        }else{
            $this->error(['code'=>2,'msg'=>'sql运行失败']);
        }


    }

    /**
郭盛 authored
2011 2012 2013 2014 2015 2016 2017
     * @ApiTitle    (我的订单)
     * @ApiSummary  (我的订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/myorder)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="type", type="inter", required=false, description="状态(不传默认为全部 1为待支付 2为已完成)")
郭盛 authored
2018 2019
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
郭盛 authored
2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "id":       //用户ID
            "pic_id": //图片,
            "video_id":   //视频,
            "status" :   //状态(1待支付 2已完成)
郭盛 authored
2030
            "total"://总价格
郭盛 authored
2031 2032 2033 2034 2035 2036
        }
        })
     */
    public function myorder()
    {
        $user_id = $this->uid;
郭盛 authored
2037 2038
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
郭盛 authored
2039
        $type = $this->request->param('type');
郭盛 authored
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105
        $res = Db::name('user')
            ->where('id',$user_id)
            ->field('id,is_vip')
            ->find();
        //确认为会员
        if($res['is_vip'] == 1){
            //判断状态
            if(empty($type)){
                //全部
                $res = Db::name('order')
                    ->where('user_id',$user_id)
                    ->field('id,pic_id,video_id,status,total')
                    ->order('createtime desc,id desc')
                    ->page($page,$pageNum)
                    ->select();
                $res = $this->fetch($res);
                $this->success('SUCCESS',$res);
            }elseif ($type == 1){
                //待支付
                $res = Db::name('order')
                    ->where('user_id',$user_id)
                    ->where('status',1)
                    ->field('id,pic_id,video_id,status,total')
                    ->order('createtime desc,id desc')
                    ->page($page,$pageNum)
                    ->select();
                $res = $this->fetch($res);
                $this->success('SUCCESS',$res);
            }else{
                //已完成
                $res = Db::name('order')
                    ->where('user_id',$user_id)
                    ->where('status',2)
                    ->field('id,pic_id,video_id,status,total')
                    ->order('createtime desc,id desc')
                    ->page($page,$pageNum)
                    ->select();
                $res = $this->fetch($res);
                $this->success('SUCCESS',$res);
            }
        }else{
            //不是会员的状态
            //判断状态
            if(empty($type)){
                $res = Db::name('order')
                    ->where('user_id',$user_id)
                    ->field('id,pic_id,video_id,status,total')
                    ->order('createtime desc,id desc')
                    ->page($page,$pageNum)
                    ->select();
                $res = $this->fetch1($res);
                $this->success('SUCCESS',$res);
            }elseif ($type == 1){
                $res = Db::name('order')
                    ->where('user_id',$user_id)
                    ->where('status',1)
                    ->field('id,pic_id,video_id,status,total')
                    ->order('createtime desc,id desc')
                    ->page($page,$pageNum)
                    ->select();
                $res = $this->fetch1($res);
                $this->success('SUCCESS',$res);
            }else{
                $res = Db::name('order')
                    ->where('user_id',$user_id)
                    ->where('status',2)
郭盛 authored
2106
                    ->field('id,pic_id,video_id,status,total,num')
郭盛 authored
2107 2108 2109 2110 2111 2112 2113 2114
                    ->order('createtime desc,id desc')
                    ->page($page,$pageNum)
                    ->select();
                $res = $this->fetch1($res);
                $this->success('SUCCESS',$res);
            }
        }
    }
郭盛 authored
2115
郭盛 authored
2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199

    /**
     * @ApiTitle    (苹果完成订单)
     * @ApiSummary  (苹果完成订单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/iphone_finish_order)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "info": [
    {
    "id": 13,
    "user_id": 10,
    "pic_id": null,
    "video_id": {
    "id": "1346",
    "attr": "2K",
    "vipprice": 1350,
    "thumbnail": "http://qiniuareial.w.broing.cn/uploads/20200811/Fmpouw8DlCJYxSCSveIh2fjlhG9i.gif"
    },
    "total": 1350,
    "status": 2,
    "num": "2020081299101519",
    "createtime": 1597232108,
    "updatetime": 1597232127
    },
    {
    "id": 22,
    "user_id": 10,
    "pic_id": 31,
    "video_id": null,
    "total": 2250,
    "status": 2,
    "num": "2020081810151565",
    "createtime": 1597747902,
    "updatetime": null
    }
    ],
    "is_vip": "1"
    }
    })
     */
    public function iphone_finish_order()
    {
        $user_id = $this->auth->id;
        $user = Db::name('user')->where('id',$user_id)->field('id,is_vip')->find();
        $data['info'] = Db::name('iphone')
            ->where('user_id',$user_id)
            ->where('status',2)
            ->select();
        $rule = config('verify.path');
        foreach ($data['info'] as &$v){
            if(!empty($v['pic_id'])){
                $v1 = Db::name('pic')->field('id,title,thumbnail,url,code,price,number')->where('id',$v['pic_id'])->find();
                $v1['thumbnail'] = $rule.$v1['thumbnail'];
                $v1['vipprice'] = $v1['price']*0.75;
            }
            if(!empty($v['video_id'])){
                $v['video_id'] = unserialize($v['video_id']);
                $info = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v['video_id']['id'])->find();
                if($v['video_id']['attr'] == 1){
                    $v['video_id']['attr'] = '2K';
                    $v['video_id']['vipprice'] = $info['price']*0.75;
                }elseif ($v['video_id']['attr'] == 2){
                    $v['video_id']['attr'] = '4K';
                    $v['video_id']['four_vipprice'] = $info['four_price'] * 0.75;
                }else{
                    $v['video_id']['attr'] = '8K';
                    $v['video_id']['eight_vipprice'] =$info['eight_price'] * 0.75;
                }
                $v['video_id']['thumbnail'] = $rule.$info['thumbnail'];

            }
        }
        $data['is_vip'] = $user['is_vip'];
        $this->success('success',$data);
    }

郭盛 authored
2200 2201 2202 2203 2204 2205 2206 2207
    //会员
    public function fetch($res)
    {
        $rule = config('verify.path');
        foreach ($res as &$v){
            if(!empty($v['pic_id'])){
                $v['pic_id'] = explode(',',$v['pic_id']);
                foreach ($v['pic_id'] as &$v1){
郭盛 authored
2208
                    $v1 = Db::name('pic')->field('id,title,thumbnail,url,code,price,number')->where('id',$v1)->find();
郭盛 authored
2209 2210
                    $v1['thumbnail'] = $rule.$v1['thumbnail'];
                    $v1['vipprice'] = $v1['price']*0.75;
郭盛 authored
2211 2212
                }
            }
郭盛 authored
2213 2214
            if(!empty($v['video_id'])){
                $v['video_id'] = unserialize($v['video_id']);
郭盛 authored
2215 2216 2217 2218 2219 2220 2221 2222 2223
                foreach ($v['video_id'] as &$v2){
                    $v2['info'] = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v2['id'])->find();
                    $v2['info']['attr'] = $v2['attr'];
                    unset($v2['attr']);
                    $v2['info']['thumbnail'] = $rule.$v2['info']['thumbnail'];
                    $v2['info']['vipprice'] = $v2['info']['price']*0.75;
                    $v2['info']['four_vipprice'] = $v2['info']['four_price'] * 0.75;
                    $v2['info']['eight_vipprice'] = $v2['info']['eight_price'] * 0.75;
                }
郭盛 authored
2224
            }
郭盛 authored
2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236
        }
        return $res;
    }

    //非会员
    public function fetch1($res)
    {
        $rule = config('verify.path');
        foreach ($res as &$v){
            if(!empty($v['pic_id'])){
                $v['pic_id'] = explode(',',$v['pic_id']);
                foreach ($v['pic_id'] as &$v1){
郭盛 authored
2237
                    $v1 = Db::name('pic')->field('id,title,thumbnail,url,code,price,number')->where('id',$v1)->find();
郭盛 authored
2238
                    $v1['thumbnail'] = $rule.$v1['thumbnail'];
郭盛 authored
2239
                }
郭盛 authored
2240 2241 2242 2243 2244 2245 2246 2247
            }
            if(!empty($v['video_id'])){
                $v['video_id'] = unserialize($v['video_id']);
                foreach ($v['video_id'] as &$v2){
                    $v2['info'] = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v2['id'])->find();
                    $v2['info']['attr'] = $v2['attr'];
                    unset($v2['attr']);
                    $v2['info']['thumbnail'] = $rule.$v2['info']['thumbnail'];
郭盛 authored
2248 2249 2250
                }
            }
        }
郭盛 authored
2251
        return $res;
郭盛 authored
2252 2253
    }
郭盛 authored
2254 2255 2256 2257 2258 2259 2260
    /**
     * @ApiTitle    (消费记录)
     * @ApiSummary  (消费记录)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/payhistory)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
郭盛 authored
2261 2262 2263
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     *
郭盛 authored
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
          "times"://时间分段,
          "info":[
                "id": 4,//id,
                "user_id"://用户ID
                "pic_id"://图片ID
                "video_id"://视频ID
          ],
          "total"://总价
        }
        })
     */
    public function payhistory()
    {
郭盛 authored
2282 2283
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
郭盛 authored
2284 2285
        $rule = config('verify.path');
        $user_id = $this->uid;
郭盛 authored
2286 2287 2288 2289
        $res = Db::name('user')
            ->where('id',$user_id)
            ->field('id,is_vip')
            ->find();
郭盛 authored
2290 2291 2292 2293 2294
        $data = Db::name('order')
            ->field('id,user_id,pic_id,video_id,total,createtime')
            ->where('user_id',$user_id)
            ->where('status',2)
            ->order('createtime desc,id desc')
郭盛 authored
2295
            ->page($page,$pageNum)
郭盛 authored
2296
            ->select();
郭盛 authored
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320
        //判断该用户是否为会员
        if($res['is_vip'] == 1){
            //是的情况
            foreach ($data as &$v){
                $v['createtime'] = date('Y-m-d',$v['createtime']);
                if(!empty($v['pic_id'])){
                    $v['pic_id'] = explode(',',$v['pic_id']);
                    foreach ($v['pic_id'] as &$v1){
                        $v1 = Db::name('pic')->field('id,title,thumbnail,url,code,price')->where('id',$v1)->find();
                        $v1['thumbnail'] = $rule.$v1['thumbnail'];
                        $v1['vipprice'] = $v1['price']*0.75;
                    }
                }
                if(!empty($v['video_id'])){
                    $v['video_id'] = unserialize($v['video_id']);
                    foreach ($v['video_id'] as &$v2){
                        $v2['info'] = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v2['id'])->find();
                        $v2['info']['attr'] = $v2['attr'];
                        unset($v2['attr']);
                        $v2['info']['thumbnail'] = $rule.$v2['info']['thumbnail'];
                        $v2['info']['vipprice'] = $v2['info']['price']*0.75;
                        $v2['info']['four_vipprice'] = $v2['info']['four_price'] * 0.75;
                        $v2['info']['eight_vipprice'] = $v2['info']['eight_price'] * 0.75;
                    }
郭盛 authored
2321 2322
                }
            }
郭盛 authored
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341
        }else{
            //否的情况
            foreach ($data as &$v){
                $v['createtime'] = date('Y-m-d',$v['createtime']);
                if(!empty($v['pic_id'])){
                    $v['pic_id'] = explode(',',$v['pic_id']);
                    foreach ($v['pic_id'] as &$v1){
                        $v1 = Db::name('pic')->field('id,title,thumbnail,url,code,price')->where('id',$v1)->find();
                        $v1['thumbnail'] = $rule.$v1['thumbnail'];
                    }
                }
                if(!empty($v['video_id'])){
                    $v['video_id'] = unserialize($v['video_id']);
                    foreach ($v['video_id'] as &$v2){
                        $v2['info'] = Db::name('video')->field('keyword,type_ids,content,is_recommend,buy_num,click_num,createtime,updatetime',true)->where('id',$v2['id'])->find();
                        $v2['info']['attr'] = $v2['attr'];
                        unset($v2['attr']);
                        $v2['info']['thumbnail'] = $rule.$v2['info']['thumbnail'];
                    }
郭盛 authored
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363
                }
            }
        }
        //将用户购买时间数据分段
        $times = array_values(array_unique(array_column($data,'createtime')));
        rsort($times);
        //将数据放到对应的时间分段
        $arr = [];
        foreach ($times as $t_k=> $t_v){
            $arr[$t_k]['times'] = $t_v;
            $k = 0;
            foreach ($data as $value){
                $k+=0;
                if($t_v == $value['createtime']){
                    $arr[$t_k]['info'][$k] = $value;
                    $k++;
                }
            }
        }
        $this->success('SUCCESS',$arr);
    }
郭盛 authored
2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381
    /**
     * @ApiTitle    (获取sessionkey)
     * @ApiSummary  (获取sessionkey)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/getSessionKey)
     *
     * @ApiParams   (name="code", type="string", required=true, description="code")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data":[
        "session_key"://session_key
    ]
    })
     */
    public function getSessionKey(){
郭盛 authored
2382
        $rule = config('verify.raw');
郭盛 authored
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397
        $validate = new Validate([
            'code'           => 'require',
        ]);

        $validate->message([
            'code.require'           => '缺少参数code!',
        ]);

        $data = $this->request->param();
        if (!$validate->check($data)) {
            $this->error(['code'=>'40003','msg'=>$validate->getError()]);
        }

        $code      = $data['code'];
        $appId = $rule['app_id'];
郭盛 authored
2398
郭盛 authored
2399 2400 2401
        $appSecret = $rule['secret'];

        $response = "https://api.weixin.qq.com/sns/jscode2session?appid=$appId&secret=$appSecret&js_code=$code&grant_type=authorization_code";
郭盛 authored
2402
        $response = $this->http_get($response);
郭盛 authored
2403 2404 2405 2406 2407 2408 2409
        $response = json_decode($response, true);
        if (!empty($response['errcode'])) {
            $this->error(['code'=>'2','msg'=>'操作失败:'.$response['errcode']]);
        }
        $this->success('获取成功',$response);
    }
郭盛 authored
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423
    //curl  get请求
    public function http_get($url){
        $curl = curl_init();//启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL,$url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, false);//不开启header
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
        $result = curl_exec($curl); //执行操作
        curl_close($curl);
        return $result;
    }
郭盛 authored
2424 2425 2426 2427 2428 2429 2430
    /**
     * @ApiTitle    (获取用户手机号)
     * @ApiSummary  (获取用户手机号)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/getMobile)
     *
     * @ApiParams   (name="sessionKey", type="string", required=true, description="sessionkey")
郭盛 authored
2431
     * @ApiParams   (name="encryptedData", type="string", required=true, description="encryptedDate")
郭盛 authored
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
     * @ApiParams   (name="iv", type="string", required=true, description="iv")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
          "data":[
               "phoneNumber"://手机号
          ]
        })
     */
    public function getMobile()
    {
郭盛 authored
2445
        $appid = 'wx4300d933e5abd5ba';
郭盛 authored
2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462
        $sessionKey = $this->request->param('sessionKey');
        $encryptedData = $this->request->param('encryptedData');
        $iv = $this->request->param('iv');
        $errCode = $this->decryptData($appid,$sessionKey,$encryptedData, $iv, $data );
        if ($errCode == 0) {
            $return['tel'] = $data->phoneNumber;
            $return['tel'] = json_encode($return['tel']);
            $return['tel'] = json_decode($return['tel'],true);
        } else {
            $return['code'] = 301;
            $return['data'] = $errCode;
            $return['code'] = json_encode($return['code']);
            $return['code'] = json_decode($return['code'],true);
            $return['data'] = json_encode($return['data']);
            $return['data'] = json_decode($return['data'],true);
        }
郭盛 authored
2463
        $this->success('SUCCESS',$return);
郭盛 authored
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494
    }

    private function decryptData( $appid,$sessionKey,$encryptedData, $iv, &$data )
    {
        if (strlen($sessionKey) != 24) {
            return -41001;
        }
        $aesKey=base64_decode($sessionKey);

        if (strlen($iv) != 24) {
            return -41002;
        }
        $aesIV=base64_decode($iv);

        $aesCipher=base64_decode($encryptedData);

        $result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);

        $dataObj=json_decode( $result );
        if( $dataObj  == NULL )
        {
            return -41003;
        }
        if( $dataObj->watermark->appid != $appid )
        {
            return -41004;
        }
        $data = $dataObj;
        return 0;
    }
郭盛 authored
2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513
    /**
     * @ApiTitle    (绑定用户手机号)
     * @ApiSummary  (绑定用户手机号)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/phone)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="phone", type="string", required=true, description="手机号")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        })
     */
    public function phone()
    {
        $user_id = $this->uid;
郭盛 authored
2514 2515 2516 2517
        $phone = $this->request->post('phone');
        if(empty($phone)){
            $this->error(['code'=>2,'msg'=>'缺少必要参数']);
        }
郭盛 authored
2518 2519 2520
        $data = Db::name('user')
            ->where('id',$user_id)
            ->update(['mobile'=>$phone]);
郭盛 authored
2521 2522 2523 2524 2525
        if(!empty($data)){
            $this->success('SUCCESS',$data);
        }else{
            $this->error(['code'=>2,'msg'=>'sql运行失败']);
        }
郭盛 authored
2526
    }
郭盛 authored
2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538


    /**
     * @ApiTitle    (填写发票信息)
     * @ApiSummary  (填写发票信息)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/invoice)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="order_id", type="inter", required=true, description="订单ID")
     * @ApiParams   (name="name", type="string", required=true, description="公司名称")
郭盛 authored
2539 2540
     * @ApiParams   (name="tel", type="string", required=true, description="公司电话")
     * @ApiParams   (name="adress", type="string", required=true, description="公司地址")
郭盛 authored
2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556
     * @ApiParams   (name="duty", type="string", required=true, description="纳税人识别号")
     * @ApiParams   (name="bank", type="string", required=true, description="银行名称")
     * @ApiParams   (name="card", type="string", required=true, description="银行账号")
     * @ApiParams   (name="linkname", type="string", required=true, description="收件人名字")
     * @ApiParams   (name="linktel", type="string", required=true, description="收件人电话")
     * @ApiParams   (name="linkadress", type="string", required=true, description="收件人地址")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        })
     */
    public function invoice()
    {
        $param = $this->request->param();
郭盛 authored
2557
        $param['user_id'] = $this->uid;
郭盛 authored
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584
        $validate = new Validate([
            'order_id'=>'require',
            'name'=>'require',
            'tel'=>'require',
            'adress'=>'require',
            'duty'=>'require',
            'bank'=>'require',
            'card'=>'require',
            'linkname'=>'require',
            'linktel'=>'require',
            'linkadress'=>'require',
        ]);
        $validate->message([
            'order_id'=>'订单ID不能为空',
            'name'=>'公司名称不能为空',
            'tel'=>'公司电话不能为空',
            'adress'=>'公司地址不能为空',
            'duty'=>'纳税人识别号不能为空',
            'bank'=>'银行名称不能为空',
            'card'=>'银行账号不能为空',
            'linkname'=>'收件人姓名不能为空',
            'linktel'=>'收件人电话不能为空',
            'linkadress'=>'收件人地址不能为空',
        ]);
        if (!$validate->check($param)) {
            $this->error($validate->getError());
        }
郭盛 authored
2585
        $info = Db::name('invoice')
郭盛 authored
2586
            ->whereLike('order_id',"%$param[order_id]%")
郭盛 authored
2587 2588 2589 2590
            ->find();
        if(!empty($info)){
            $this->error(['code'=>2,'msg'=>'您已经提交过发票了']);
        }
郭盛 authored
2591 2592 2593 2594
        $param['createtime'] = time();
        $data = Db::name('invoice')
            ->insertGetId($param);
        if(!empty($data)){
郭盛 authored
2595 2596 2597 2598 2599 2600 2601
            $res = Db::name('invoice')
                ->where('id',$data)
                ->find();
            $order_id = explode(',',$res['order_id']);
            Db::name('order')
                ->whereIn('id',$order_id)
                ->update(['invoice_status'=>1]);
郭盛 authored
2602 2603 2604 2605 2606
            $this->success('success');
        }else{
            $this->error('sql运行失败');
        }
    }
郭盛 authored
2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619

    /**
     * @ApiTitle    (填写授权书信息)
     * @ApiSummary  (填写授权书信息)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/show)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="order_id", type="inter", required=true, description="订单ID")
     * @ApiParams   (name="name", type="string", required=true, description="使用人")
     * @ApiParams   (name="use", type="string", required=true, description="用途")
     * @ApiParams   (name="tel", type="string", required=true, description="联系方式")
郭盛 authored
2620
     * @ApiParams   (name="email", type="string", required=true, description="邮箱地址")
郭盛 authored
2621 2622 2623 2624 2625 2626 2627 2628 2629 2630
     *
     * @ApiReturn({
            "code": 1,
            "msg": "成功",
            "time": "1571492001",
            })
     */
    public function show()
    {
        $param = $this->request->param();
郭盛 authored
2631
        //验证器验证
郭盛 authored
2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
        $validate = new Validate([
            'order_id'=>'require',
            'name'=>'require',
            'use'=>'require',
            'tel'=>'require',
        ]);
        $validate->message([
            'order_id'=>'订单ID不能为空',
            'name'=>'使用方不能为空',
            'tel'=>'联系方式不能为空',
            'use'=>'使用用途不能为空',
        ]);
        if (!$validate->check($param)) {
            $this->error($validate->getError());
        }
郭盛 authored
2647
郭盛 authored
2648 2649 2650 2651 2652
        $res['user_id'] = $this->uid;
        $res['name'] = $param['name'];
        $res['use'] = $param['use'];
        $res['tel'] = $param['tel'];
        $res['createtime'] = time();
郭盛 authored
2653
        $res['order_id'] = ','.$param['order_id'].',';
郭盛 authored
2654
郭盛 authored
2655
        $order = explode(',',trim($res['order_id'],','));
郭盛 authored
2656 2657 2658 2659 2660 2661 2662 2663 2664
        $shou = Db::name('shou')
            ->where('user_id',$res['user_id'])
            ->column('order_id');
        foreach ($shou as $s_value){
            $s_arr = explode(',',$s_value);
            foreach ($order as $item) {
                if(in_array($item,$s_arr)){
                    $this->error('包含已下载过的授权书');
                }
郭盛 authored
2665
            }
2666
        }
郭盛 authored
2667 2668 2669 2670 2671 2672 2673
        $data = Db::name('shou')
            ->insertGetId($res);
        if(!empty($data)){
            //添加成功
            $list = Db::name('shou')
                ->where('id',$data)
                ->find();
郭盛 authored
2674
            $list['order_id'] = explode(',',$list['order_id']);
郭盛 authored
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687
            //下方改变状态用到
            $gai_order['order_id'] = $list['order_id'];
            //拼接订单号
            $order_num = Db::name('order')->whereIn('id',$list['order_id'])->field('num,createtime')->select();
            $num = implode(',',array_column($order_num,'num'));
            //拼接素材购买时间
            $time = [];
            foreach ($order_num as $v_time){
                $create_time = date('Y-m-d H:i:s',$v_time['createtime']);
                array_push($time,$create_time);
            }
            $time = implode(',',$time);
            //查询出所有的素材编号
郭盛 authored
2688
            foreach ($list['order_id'] as &$v){
郭盛 authored
2689
                //查询出订单表中的图片以及视频ID
郭盛 authored
2690 2691 2692 2693
                $v = Db::name('order')
                    ->field('pic_id,video_id')
                    ->where('id',$v)
                    ->find();
郭盛 authored
2694
                //图片ID不为空的情况
郭盛 authored
2695
                if(!empty($v['pic_id'])){
郭盛 authored
2696 2697 2698
                    $pic_id = explode(',',$v['pic_id']);
                    $v['pic_num'] = Db::name('pic')
                        ->whereIn('id',$pic_id)
郭盛 authored
2699
                        ->column('number');
郭盛 authored
2700 2701
                }else{
                    $v['pic_num'] = [];
郭盛 authored
2702
                }
郭盛 authored
2703
                //视频ID不为空的情况
郭盛 authored
2704
                if(!empty($v['video_id'])){
郭盛 authored
2705 2706 2707 2708
                    $video_id = unserialize($v['video_id']);
                    $v_id = array_column($video_id,'id');
                    $v['video_num'] = Db::name('video')
                        ->whereIn('id',$v_id)
郭盛 authored
2709
                        ->column('number');
郭盛 authored
2710 2711
                }else{
                    $v['video_num'] = [];
郭盛 authored
2712 2713
                }
            }
郭盛 authored
2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724
            //拼接所有素材的唯一编号
            $str = '';
            foreach($list['order_id'] as $l_value){
                $pic_str = implode(',',$l_value['pic_num']);
                $video_str = implode(',',$l_value['video_num']);
                if(!empty($pic_str)){
                    $str .= $pic_str.',';
                }
                if(!empty($video_str)){
                    $str .= $video_str.',';
                }
郭盛 authored
2725
            }
郭盛 authored
2726 2727 2728 2729 2730 2731

            //修改订单表中的授权书状态为已下载
            foreach ($gai_order['order_id'] as $v_o){
                Db::name('order')
                    ->where('id',$v_o)
                    ->update(['shou_status'=>1]);
郭盛 authored
2732
            }
郭盛 authored
2733
            $common = new Common();
郭盛 authored
2734
            $common->test_pdf($res['name'],$res['use'],$res['tel'],$str,$num,$time,$param['email']);
郭盛 authored
2735
        }else{
郭盛 authored
2736
            $this->error('加入授权书表失败');
郭盛 authored
2737 2738 2739
        }
    }
郭盛 authored
2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760
    /**
     * @ApiTitle    (投诉与建议)
     * @ApiSummary  (投诉与建议)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/suggest)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="title", type="string", required=true, description="标题")
     * @ApiParams   (name="content", type="string", required=true, description="内容")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        })
     */
    public function suggest()
    {
        $param = $this->request->param();
        $param['user_id'] = $this->uid;
郭盛 authored
2761
        $param['createtime'] = time();
郭盛 authored
2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781
        $validate = new Validate([
            'title'=>'require',
            'content'=>'require',
        ]);
        $validate->message([
            'title'=>'标题不能为空',
            'content'=>'内容不能为空',
        ]);
        if (!$validate->check($param)) {
            $this->error($validate->getError());
        }
        $data = Db::name('suggest')
            ->insertGetId($param);
        if(!empty($data)){
            $this->success('添加成功');
        }else{
            $this->error('sql运行失败');
        }
    }
郭盛 authored
2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795
    /**
     * @ApiTitle    (切换数值)
     * @ApiSummary  (切换数值)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user/change)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        })
     */
    public function change()
    {
郭盛 authored
2796
        $this->success('success',['type'=>1]);
unknown authored
2797
郭盛 authored
2798 2799 2800
    }

郭盛 authored
2801
}