AdminRentStatusController.php 5.6 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\model\ChangeRentModel;
use app\portal\model\ConditionModel;
use app\portal\model\VehicleModel;
use cmf\controller\AdminBaseController;
use app\portal\model\PortalPostModel;
use app\portal\service\PostService;
use app\portal\model\PortalCategoryModel;
use think\Db;
use app\admin\model\ThemeModel;
use think\Loader;

/**
 * Class AdminRentStatusController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'租车商品申请管理',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'租车商品申请管理'
 * )
 */
class AdminRentStatusController extends AdminBaseController
{
    /**
     * 更改租车商品状态申请
     * @adminMenu(
     *     'name'   => '更改租车商品状态申请',
     *     'parent' => 'portal/AdminRentStatus/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '更改租车商品状态申请',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $data = $this->request->param();
        $name_arr = array();
        $return = $this->adminIndex($data);
        $ret = $return['page_arr'];
        if(!empty($return['where_arr']['create_time'])){
            $where_change['c.create_time'] = $return['where_arr']['create_time'];
        }
        //        商品码
        if(!empty($data['keyword'])){
            $where_change['c.goods_num'] = array('like','%'.$data['keyword'].'%');
            $ret['keyword'] = $data['keyword'];
            $this->assign('keyword',$data['keyword']);
        }
        //        店铺名
        if(!empty($data['store'])){
            $ret['store'] = $data['store'];
            $where_change['c.store_id'] = $data['store'];
            $this->assign('store_id',$data['store']);
        }
        $where_change['c.status'] = array('neq',9);
        $list = Db::name('ChangeRent')->alias('c')
            ->where($where_change)
            ->join('Store s','s.id = c.store_id')
            ->join('Vehicle v','v.id = c.vehicle_id')
            ->join('Condition d','d.id = c.status_id')
            ->field('v.name , s.store_name,s.id as store_id , d.content,c.*')
            ->order('c.create_time desc')
            ->paginate(10,false,['query'=>$ret]);
        $where_store['status'] = array('neq',9);
        $store= Db::name('Store')
            ->where($where_store)
            ->select()->toArray();
//        foreach ($store as $k=>$v){
//            if(!in_array($v['store_name'],$name_arr)) {
//                $name_arr[] = $v['store_name'];
//                $middle_arr['store_name'] = $v['store_name'];
//                $middle_arr['store_id'] = $v['store_id'];
//                $arr[] = $middle_arr;
//            }
//        }
        $page = $list->render();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->assign('store', $store);
        return $this->fetch();
    }



    /**
     * 更改租车商品状态
     * @adminMenu(
     *     'name'   => '更改租车商品状态',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '更改租车商品状态',
     *     'param'  => ''
     * )
     */
    public function agree()
    {
        $data   = $this->request->param();
        $where_status['id'] = $data['id'];
        $where_status['status'] = 2;
        $status = Db::name('ChangeRent')->where($where_status)->find();
        if($status){
            if($data['status'] == 3 ){
//                同意
                $where_rent['goods_id'] = $status['vehicle_id'];
                $where_rent['store_id'] = $status['store_id'];
                $where_rent['goods_num'] = $status['goods_num'];
                $update_rent['condition_id'] = $status['status_id'];
                $update_rent['update_time'] = time();
                $res_rent = Db::name('Rent')->where($where_rent)->update($update_rent);
                if(!$res_rent){
                    $this->apiResponse('0','操作失败');
                }
            }
            $update['status'] = $data['status'];
            $update['update_time'] = time();
            $res = Db::name('ChangeRent')->where($where_status)->update($update);
            if($res){
                $this->apiResponse('1','操作成功');
            }else{
                $this->apiResponse('0','操作失败');
            }
        }else{
            $this->apiResponse('0','状态错误');
        }
    }

    /**
     * 删除申请
     * @adminMenu(
     *     'name'   => '删除申请',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除申请',
     *     'param'  => ''
     * )
     */
    public function del()
    {
        $model = new ChangeRentModel();
        $this->adminDel($model);
    }





}