<?php
namespace app\api\controller\h5;

use app\common\util\AppMsg;
use app\hander\HelpHander;
use think\Controller;
use think\Db;
use think\Exception;

class Worker extends Base
{

      //推荐护工
    public function hot(){
        $model = new \app\common\model\Worker();
        $data = $model->hotList($this->orgId);
        HelpHander::success($data);
    }

    // 护工列表
    public function lists(){
        $page = input('page',1);
        $size = input('size',10);
        $model = new \app\common\model\Worker();
        $res = $model->apiLists($this->orgId,[],$page,$size);
        HelpHander::success($res['rows'],'操作成功');
    }

    // 用户下单
    public function order(){
        $depId = input('depId/d',0);
        $model = new \app\common\model\PhOrders();
        $res = $model->bookOrder();
        if(!$res){
            HelpHander::error($model->getError());
        }
        $ids = Db::table('ph_user')
            ->where('org_id',$this->orgId)
            ->where('','exp',Db::raw("FIND_IN_SET($depId,dep)"))
            ->column('user');
        if (!empty($ids)) {
            send_jpush($ids,AppMsg::PUSH_WORKER_ORDER_SEND,'有一个新的陪护订单,请注意查看',['id'=>$res]);
        }
        HelpHander::success(['payId'=>$res],'操作成功');
    }

    public function userInfo(){
        $info  = Db::name('wxuser')
            ->where('id',$this->userId)
            ->find();
        HelpHander::success($info);
    }

    // 护工列表
    public function cates(){
        $lists = Db::name('cate')->where('org_id',$this->orgId)->where('enable',1)->where('del',0)->select();
        $lists = $lists?$lists:[];
        foreach ($lists as $k=>$v){
            $lists[$k]['title'] = $v['title']."[单价:".$v['price']."]";
        }
        HelpHander::success($lists,'操作成功');
    }
}