Index.php 9.9 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页接口
     * @ApiTitle    (服务商申请)
     * @ApiSummary  (服务商申请)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/SellerStatus)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="CompanyMain", type="integer", required=true, description="公司主营业务")
     * @ApiParams   (name="CompanyType", type="string", required=true, description="申请业务类型:1=换电商,2=经营商,3=维修商,4=代理商")
     * @ApiParams   (name="Person", type="string", required=true, description="负责人")
     * @ApiParams   (name="Mobile", type="string", required=true, description="联系电话")
     * @ApiParams   (name="PersonEmail", type="string", required=true, description="负责人邮箱地址")
     * @ApiParams   (name="BusinessPeople", type="string", required=true, description="业务专员")
     * @ApiParams   (name="BusinessPeopleEmail", type="string", required=true, description="业务专员邮箱地址")
     * @ApiParams   (name="OpenBank", type="string", required=true, description="开户银行")
     * @ApiParams   (name="Number", type="string", required=true, description="账号")
     * @ApiParams   (name="LastYearMoney", type="string", required=true, description="上年营业额")
     * @ApiParams   (name="CompanyPeopleNum", type="string", required=true, description="公司员工数")
     * @ApiParams   (name="image", type="string", required=true, description="营业执照或负责人身份证照片")
     * @ApiParams   (name="Status", type="string", required=true, description="审核状态:0=待审核,1=审核通过,2=审核未通过")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function SellerStatus()
    {
        $UserId = $this->IsToken($this->request->header());
        //验证申请是否唯一
        $this->OnlySeller($UserId);
        $params = $this->MyParams();
        $params['user_id'] = $UserId;
        $params['Status'] = 0;
        $params['createtime'] = time();
        $params['updatetime'] = time();
        try {
            $Res = Db::name('seller')->insert($params);
        } catch (\Exception  $e) {
            $this->error($e->getMessage());
        }
        $this->Res($Res);
    }


    /**
     * 首页接口
     * @ApiTitle    (新增/更改门店)
     * @ApiSummary  (新增/更改门店)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/InsertUpdateStor)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="type", type="integer", required=true, description="类型:1=新增,2=更改")
     * @ApiParams   (name="id", type="integer", required=true, description="门店ID/新增时不传")
     * @ApiParams   (name="avatar", type="string", required=true, description="门牌照")
     * @ApiParams   (name="name", type="string", required=true, description="店铺名称")
     * @ApiParams   (name="address", type="string", required=true, description="店铺位置")
     * @ApiParams   (name="lng", type="string", required=true, description="经度")
     * @ApiParams   (name="lat", type="string", required=true, description="纬度")
     * @ApiParams   (name="address_con", type="string", required=true, description="详细地址")
     * @ApiParams   (name="mobile", type="string", required=true, description="联系电话")
     * @ApiParams   (name="hours", type="string", required=true, description="营业时间")
     * @ApiParams   (name="Battery", type="string", required=true, description="电池分类Json数组['type_id':'1','num':'10']")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function InsertUpdateStor()
    {
        $UserId = $this->IsToken($this->request->header());
        $params = $this->request->param();
        if ($params['type'] == 1) {
            $data = [
                'user_id' => $UserId,
                'createtime' => time(),
                'updatetime' => time(),
                'avatar' => $params['avatar'],
                'name' => $params['name'],
                'address' => $params['address'],
                'lng' => $params['lng'],
                'lat' => $params['lat'],
                'address_con' => $params['address_con'],
                'mobile' => $params['mobile'],
                'hours' => $params['hours'],
                'Battery' => $params['Battery'],
            ];
            $Res = Db::name('stor')->insert($data);
        } else {
            $data = [
                'updatetime' => time(),
                'avatar' => $params['avatar'],
                'name' => $params['name'],
                'address' => $params['address'],
                'lng' => $params['lng'],
                'lat' => $params['lat'],
                'address_con' => $params['address_con'],
                'mobile' => $params['mobile'],
                'hours' => $params['hours'],
                'Battery' => $params['Battery'],
            ];
            $Res = Db::name('stor')->where('id', $params['id'])->update($data);
        }
        $this->Res($Res);
    }


    /**
     * 首页接口
     * @ApiTitle    (门店更改回显)
     * @ApiSummary  (门店更改回显)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/UpdateStorBack)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="integer", required=true, description="门店ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function UpdateStorBack()
    {
        $UserId = $this->IsToken($this->request->header());
        $ID = input('id');
        $Arr = Db::name('stor')->where('id', $ID)->where('user_id', $UserId)->find();
        if (empty($Arr)) {
            $this->error('参数错误', 0);
        }
        $BatteryArr = json_decode($Arr['Battery'], true);
        $data = [
            'avatar' => cdnurl($Arr['avatar']),
            'name' => $Arr['name'],
            'address' => $Arr['address'],
            'lng' => $Arr['lng'],
            'lat' => $Arr['lat'],
            'address_con' => $Arr['address_con'],
            'mobile' => $Arr['mobile'],
            'hours' => $Arr['hours'],
            'Battery' => $BatteryArr,
        ];
        $this->success('成功', $data);
    }


    /**
     * 首页接口
     * @ApiTitle    (我的门店)
     * @ApiSummary  (我的门店)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/MyStor)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="keywords", type="string", required=true, description="搜索关键字")
     * @ApiParams   (name="start", type="string", required=true, description="开始日期")
     * @ApiParams   (name="end", type="string", required=true, description="结束日期")
     * @ApiParams   (name="pages", type="string", required=true, description="pages")
     * @ApiParams   (name="rows", type="string", required=true, description="rows")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function MyStor()
    {
        $UserId = $this->IsToken($this->request->header());
        $params = $this->request->param();
        $mapA = [];
        $mapB = [];
        $mapC = [];
        if (!empty($params['keywords']) || $params['keywords'] != '' || $params['keywords'] != "" || $params['keywords'] != null) {
            $mapA['name'] = ['LIKE', '%' . $params['keywords'] . '%'];
        }
        if (!empty($params['start']) || $params['start'] != '' || $params['start'] != "" || $params['start'] != null) {
            $StartTime = strtotime($params['start']);
            $mapB['createtime'] = ['GT', $StartTime];
        }
        if (!empty($params['end']) || $params['end'] != '' || $params['end'] != "" || $params['end'] != null) {
            $EndTime = strtotime($params['end']);
            $mapC['createtime'] = ['LT', $EndTime];
        }
        $Arr = Db::name('stor')->where('user_id', $UserId)->where($mapA)->where($mapB)->where($mapC)->order('createtime desc')->page($params['pages'], $params['rows'])->select();
        $Count = Db::name('stor')->where('user_id', $UserId)->where($mapA)->where($mapB)->where($mapC)->order('createtime desc')->select();
        $StorCount = Db::name('stor')->where('user_id', $UserId)->select();
        if (empty($Arr)) {
            $data = [
                'StorCount' => count($StorCount),
                'Count' => 0,
                'List' => []
            ];
        } else {
            foreach ($Arr as $k => $v) {
                $List[$k]['id'] = $v['id'];
                $List[$k]['name'] = $v['name'];
                $List[$k]['createtime'] = date('Y.m.d', $v['createtime']);
            }
            $data = [
                'StorCount' => count($StorCount),
                'Count' => count($Count),
                'List' => $List
            ];
        }
        $this->success('成功', $data);
    }
}