where("mobile",$post['mobile'])->find(); // if(!empty($m)) { // $where[]=["o.uid","=",$m['uid']]; // } // } if(!empty($post['to_phone'])){ $where[]=["to_phone","=",$post['to_phone']]; } if(!empty($post['contract_no'])){ $where[]=["contract_no","=",$post['contract_no']]; } if(!empty($post['status'])){ $where[]=["status","=",$post['status']]; } // if(in_array((string)$post['status'],["0","1","-1"])){ // $where[]=["status","=",(int)$post['status']]; // } //创建时间 $startTime=""; $endTime=""; if(!empty($post['time'][0]) && !empty($post['time'][1])) { $startTime = strtotime($post['time'][0]); $endTime = strtotime($post['time'][1]); $where[]=["check_time","between","{$startTime},{$endTime}"]; } $order = new UserContractRecordModel(); $data = $order // ->alias("o") // ->field("*,u1.mobile,u1.nickname,a.title as show_template_title,a.imgs as show_template_imgs") // ->leftJoin("user u1","u1.uid = uid") // ->leftJoin("show_template a","a.id = show_template_id") ->field('*') ->where($where) ->page((int)$post["page"], $pageSize) ->order("id","desc") ->select() ->toArray(); $pageCount = $order->where($where)->count(); $result = UtilService::getParam([ "id", "contract_no", "uid", "phone", "address", "card", "to_uid", "to_phone", "to_address", "to_card", "status", "from_check", "to_check", "uid_img", "to_uid_img", "price", "deposit", "balance", "content", "period", // "template_id", "start_time", "end_time", "create_time", "delete_time", "check_time", // ['start_time', 'start_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], // ['end_time', 'end_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], // ['create_time', 'create_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], // ['delete_time', 'delete_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], // ['check_time', 'check_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], ], $data); return app('json')->success([ 'list' => $result, 'pageCount' => $pageCount, 'pageSize' => $pageSize, 'page' => $post['page'], ]); } /** * 合约详细 * @param Request $request * @return mixed */ public function getContractInfo(Request $request) { [$id] = UtilService::getMore([ ['id',''] ],$request,true); $adminInfo = UserContractRecordModel::where("id",$id)->find()->toArray(); return app('json')->success([ 'id' => $id, 'contract_no' =>$adminInfo['contract_no'], 'uid' => $adminInfo['uid'], 'phone' => $adminInfo['phone'], 'address' => $adminInfo['address'], 'card' =>$adminInfo['card'], 'to_uid' => $adminInfo['to_uid'], 'to_phone' => $adminInfo['to_phone'], 'to_address' => $adminInfo['to_address'], 'to_card' => $adminInfo['to_card'], 'status' => $adminInfo['status'], 'from_check' => $adminInfo['from_check'], 'to_check' => $adminInfo['to_check'], 'uid_img' => $adminInfo['uid_img'], 'to_uid_img' => $adminInfo['to_uid_img'], 'price' => $adminInfo['price'], 'deposit' => $adminInfo['deposit'], 'balance' => $adminInfo['balance'], 'content' => $adminInfo['content'], 'period' => $adminInfo['period'], 'start_time' =>$adminInfo['start_time'], 'end_time' =>$adminInfo['end_time'], 'create_time' =>$adminInfo['create_time'], 'delete_time' =>$adminInfo['delete_time'], 'check_time' =>$adminInfo['check_time'], // 'start_time' => date('Y-m-d H:i:s', $adminInfo['start_time']), // 'end_time' => date('Y-m-d H:i:s', $adminInfo['end_time']), // 'create_time' => date('Y-m-d H:i:s', $adminInfo['create_time']), // 'delete_time' => date('Y-m-d H:i:s', $adminInfo['delete_time']), // 'check_time' => date('Y-m-d H:i:s', $adminInfo['check_time']), // 'template_id' => $adminInfo['template_id'], ]); } /** * 打卡列表 * @param Request $request */ public function UserClockList(Request $request) { $pageSize = 50; $post = UtilService::getMore( [ ['page', 1], ['uid',0], //员工uid ['nickname',''], //员工名 ['contract_id', ''], //签约id ['time',[]], ], $request ); $where = []; if(!empty($post['uid'])){ $where[]=["uid","=",$post['uid']]; } // else // if(!empty($post['mobile'])){ // $m = Db::name("user")->where("mobile",$post['mobile'])->find(); // if(!empty($m)) { // $where[]=["o.uid","=",$m['uid']]; // } // } if(!empty($post['nickname'])){ $where[]=["nickname","like",$post['nickname']]; } if(!empty($post['contract_id'])){ $where[]=["contract_id","=",$post['contract_id']]; } //创建时间 $startTime=""; $endTime=""; if(!empty($post['time'][0]) && !empty($post['time'][1])) { $startTime = strtotime($post['time'][0]); $endTime = strtotime($post['time'][1]); $where[]=["create_time","between","{$startTime},{$endTime}"]; } $order = new UserClockModel; $data = $order // ->alias("o") // ->field("*,u1.mobile,u1.nickname,a.title as show_template_title,a.imgs as show_template_imgs") // ->leftJoin("user u1","u1.uid = uid") // ->leftJoin("show_template a","a.id = show_template_id") ->field('*') ->where($where) ->page((int)$post["page"], $pageSize) ->order("id","desc") ->select() ->toArray(); $pageCount = $order->where($where)->count(); $result = UtilService::getParam([ "id", "uid", "nickname", "contract_id", "longitude", "latitude", "create_time" // ['create_time', 'create_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], ], $data); return app('json')->success([ 'list' => $result, 'pageCount' => $pageCount, 'pageSize' => $pageSize, 'page' => $post['page'], ]); } /** * 评论列表 * @param Request $request */ public function contractCommentList(Request $request) { $pageSize = 50; $post = UtilService::getMore( [ ['page', 1], ['uid',0], //甲方 ['to_uid',''], //乙方 ['contract_no', ''], //签约id ['time',[]], ], $request ); $where = []; if(!empty($post['uid'])){ $where[]=["uid","=",$post['uid']]; } // else // if(!empty($post['mobile'])){ // $m = Db::name("user")->where("mobile",$post['mobile'])->find(); // if(!empty($m)) { // $where[]=["o.uid","=",$m['uid']]; // } // } if(!empty($post['nickname'])){ $where[]=["nickname","like",$post['nickname']]; } if(!empty($post['contract_id'])){ $where[]=["contract_id","=",$post['contract_id']]; } //创建时间 $startTime=""; $endTime=""; if(!empty($post['time'][0]) && !empty($post['time'][1])) { $startTime = strtotime($post['time'][0]); $endTime = strtotime($post['time'][1]); $where[]=["create_time","between","{$startTime},{$endTime}"]; } $order = new ContractCommentModel(); $data = $order // ->alias("o") // ->field("*,u1.mobile,u1.nickname,a.title as show_template_title,a.imgs as show_template_imgs") // ->leftJoin("user u1","u1.uid = uid") // ->leftJoin("show_template a","a.id = show_template_id") ->field('*') ->where($where) ->page((int)$post["page"], $pageSize) ->order("id","desc") ->select() ->toArray(); $pageCount = $order->where($where)->count(); $result = UtilService::getParam([ "id", "contract_no", "uid", "to_uid", "create_time", // ['create_time', 'create_time', function ($item) { // return empty($item) ? "-" : date('Y-m-d H:i:s', $item); // }], ], $data); return app('json')->success([ 'list' => $result, 'pageCount' => $pageCount, 'pageSize' => $pageSize, 'page' => $post['page'], ]); } // 删除评论 public function deleteComment(\think\Request $request) { $id = $request->param('id'); $article = ContractCommentModel::where('id', $id)->find(); if (!$article) { return app('json')->fail('评论不存在'); } $article->delete(); return app('json')->success(); } /** * 合约列表 * @param \app\Request $request * @return mixed */ public function getContractList(\think\Request $request) { // $pageSize = 50; // $post = UtilService::getMore([ // ['page',1], // ['pageSize',50], // ['nickname',''], //// ['uid',''], // ['parent_uid',''], // ['mobile',''], // ['status',''], // ['time',[]], // ],$request); //// $post['uid']=$request->user["uid"]; // $data = (new UserModel)->getDataList($post,"*",1); // return app('json')->success([ // 'list' => $data["list"], // 'pageCount' => $data["totalCount"], // 'pageSize' => $data["pageSize"], // 'page' => $data["page"], // ]); $post = UtilService::getMore([ ['page', 1], ['pageSize', 50], ['status',-2] //1未签约 2已签约 3已解约 ], $request); $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"]; $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"]; $where=[]; $where[]=["uid","=",$request->user["uid"]]; $totalCount = (new UserContractRecordModel)->where($where)->count(); if ($post["status"]!=-2){ $where[]=['status','=',$post["status"]]; } $data=null; if($totalCount>0){ $data = (new UserContractRecordModel) // ->field("") // ->alias("ut") // ->join("show_template t", "t.id = show_template_id","left") ->where($where) ->order("is_default", "desc") ->order("id", "desc") ->page($post["page"], $post["pageSize"]) ->select(); foreach($data as $k=>$v){ $data[$k]["is_use"] = 1;//是否已经购买或者可以使用 switch ($data[$k]["status"]){ case 0: $data[$k]["status_name"] = "未签约"; break; case 1: $data[$k]["status_name"] = "已签约"; break; case -1: $data[$k]["status_name"] = "已解约"; break; } } } $data = empty($data)?[]:$data; return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]); } /** * 甲方创建合约 */ public function form_save(Request $request){ $post = UtilService::getMore([ ['uid','0'], //甲方uid ['phone',''], //甲方手机号 ['address',''], //甲方地址 ['card',''], //甲方身份证号 ['to_uid','0'], //员工uid ['price',0], //服务费 ['deposit',0], // 定金 ['balance',0], //余款 ['period',0], // 周期天数 ['start_time',''], // 开始时间 ['end_time',''], // 结束时间 // ['uid_img',''] //甲方签名图片路径 // ['to_phone','']. // ['to_address',''], // ['to_card',''], // ['data',[]], // ['year',''], // ['month',''], // ['day',''], ],$request); $id = (int)$post["id"]; $uid = (int)$post["uid"]; if(empty($uid)){ return app('json')->fail("参数错误"); } // $year = $post['year']; // $month = $post['month']; // $day = $post['day']; // //// 检查年月日是否为空 // if (empty($year) || empty($month) || empty($day)) { // return app('json')->fail("日期参数错误"); // } // //// 创建 DateTime 对象 // $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day"); // //// 检查日期是否有效 // if (!$date || $date->format('Y-m-d') !== "$year-$month-$day") { // return app('json')->fail("无效的日期"); // } // unset($post['year']); // unset($post['month']); // unset($post['day']); //// 转换为时间戳 // $timestamp = $date->getTimestamp(); // // $post['create_time'] = $timestamp; //用户信息 // if(!empty($post["uid_img"])){ // $post['status'] = 2; // }else{ $post['status'] = 0; // } if (empty($id)){ $post['contract_no'] = makeOrderId($post['uid'],"CR"); $r = (new UserContractRecordModel)->save($post); }else{ $r = (new UserContractRecordModel)->where("id",$id)->update($post); } return app('json')->success("数据保存成功"); } /** * 甲方签约合约 */ public function check(Request $request){ $post = UtilService::getMore([ ['id',0], //合约id ['uid_img',''], //甲方签名图片路径 ['check_time','']//签约时间 // ['to_phone','']. // ['to_address',''], // ['to_card',''], // ['data',[]], // ['year',''], // ['month',''], // ['day',''], ],$request); $info = (new UserContractRecordModel)->where("id",$post["id"])->find(); if(empty($info)){ return app('json')->fail("合约不存在"); } // 检查签约时间是否为空 if (empty($post['uid_img'])) { return app('json')->fail("签字错误"); } // 检查签约时间是否为空 if (empty($post['check_time'])) { return app('json')->fail("日期参数错误"); } // $post['status'] = 1; $post['from_check'] = 1; if ($info['to_check']==1){ $post['status']==1; } // $post['contract_no'] = makeOrderId($post['uid'],"CR"); $r = (new UserContractRecordModel)->where("id",$post["id"])->update($post); return app('json')->success("数据保存成功"); } // 乙方确认 public function to_check(Request $request){ $post = UtilService::getMore([ ['id','0'], // ['to_uid_img',''], //乙方签名图片路径 ['to_phone',''], //乙方手机号 ['to_address',''], //乙方地址 ['to_card',''], //乙方身份证号 ['to_check_time','']//签约时间 ],$request); $info = (new UserContractRecordModel)->where("id",$post["id"])->find(); if(empty($info)){ return app('json')->fail("合约不存在"); } // 检查签约时间是否为空 if (empty($post['to_uid_img'])) { return app('json')->fail("签字错误"); } // 检查签约时间是否为空 if (empty($post['to_check_time'])) { return app('json')->fail("日期参数错误"); } $post['to_check'] = 1; if ($info['from_check']==1){ $post['status']==1; } $r = (new UserContractRecordModel)->where("id",$post["id"])->update($post); return app('json')->success("数据保存成功"); } // 员工签到 public function clock_in(Request $request){ $post = UtilService::getMore([ ['id','0'], //合约id ['longitude',''], //经度 ['latitude',''], //纬度 ],$request); $uid = (int)$post["uid"]; // 检查签约时间是否为空 if (empty($post['id'])) { return app('json')->fail("签字错误"); } $nickname=\app\model\api\User::where('uid',$uid)->value('nickname'); $r = (new UserContractRecordModel)->where("id",$post["id"])->save([ 'uid'=>$uid, 'nickname' => $nickname, 'longitude'=>$post['longitude'], 'latitude'=>$post['latitude'], 'contract_id'=>$post['id'], 'create_time'=>time() ]); return app('json')->success("数据保存成功"); } // 添加客户评论 public function comment(Request $request){ $post = UtilService::getMore([ ['id','0'], //合约id ['content',''], //评论内容 ],$request); $uid = (int)$post["uid"]; $info = (new UserContractRecordModel)->where("id",$post["id"])->find(); if(empty($info)){ return app('json')->fail("合约不存在"); } if ($info['status']!=1){ return app('json')->fail("只能在签约期间才能发表评论"); } // 检查签约时间是否为空 if (empty($post['id'])) { return app('json')->fail("签字错误"); } $r = (new ContractCommentModel)->save([ 'uid'=>$uid, 'contract_id'=>$post['id'], 'content'=>$post['content'], 'create_time'=>time() ]); return app('json')->success("数据保存成功"); } }