123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use app\common\library\Sms as Smslib;
- class Dispatch extends Common
- {
- protected $noNeedLogin = ['getSkillList','getReciveList'];
- protected $noNeedRight = ['*'];
-
- public function addSkillAuth() {
- $skill_id = $this->request->request('skill_id',0,"intval");
- $leaver_id = $this->request->request('leaver_id',0,"intval");
- $area_id = $this->request->request('area_id',0,"intval");
- $image = $this->request->request('image');
- $voice = $this->request->request('voice');
- $voice_time = $this->request->request('voice_time');
- $price = $this->request->request('price');
- $remarks = $this->request->request('remarks');
- if (!$skill_id || !$image || !$voice || !$remarks || !$price) {
- $this->error(__('Invalid parameters'));
- }
- $is_main = 0;
-
- $skillModel = new \app\common\model\DispatchSkill();
- $skillInfo = $skillModel->getSkillInfo($skill_id);
- if(!$skillInfo) {
- $this->error(__('未找到技能信息!'));
- }
- $authModel = new \app\common\model\DispatchAuth();
-
- $where = [];
- $where["user_id"] = $this->auth->id;
- $where["skill_id"] = $skill_id;
- $authInfo = $authModel->where($where)->find();
- if($authInfo) {
- if($authInfo["status"] == 0) $this->error(__('您已提交过认证申请,请耐心等待审核!'));
- if($authInfo["status"] == 1) $this->error(__('您已经认证过了'));
- }
- if($authModel->where(["user_id"=>$this->auth->id])->count()<=0) {
- $is_main = 1;
- }
-
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["skill_id"] = $skill_id;
- $data["leaver_id"] = $leaver_id;
- $data["area_id"] = $area_id;
- $data["image"] = $image;
- $data["voice"] = $voice;
- $data["voice_time"] = $voice_time;
- $data["price"] = $price;
- $data["is_main"] = $is_main;
- $data["image"] = $image;
- $data["remarks"] = $remarks;
- $data["createtime"] = time();
- $res = $authModel->insertGetId($data);
- if($res) {
- $this->success('申请发送成功,请耐心等待审核!');
- } else {
- $this->error(__('网络错误,请稍后重试!'));
- }
- }
-
- public function skillIsAuth() {
- $skill_id = $this->request->request('skill_id',0,"intval");
- if (!$skill_id) {
- $this->error(__('Invalid parameters'));
- }
- $authModel = new \app\common\model\DispatchAuth();
-
- $where = [];
- $where["user_id"] = $this->auth->id;
- $where["skill_id"] = $skill_id;
- $authInfo = $authModel->field("status")->where($where)->find();
- if($authInfo) {
- if($authInfo["status"] == 0) $this->error(__('当前技能已提交过认证申请,请耐心等待审核!'));
- if($authInfo["status"] == 1) $this->error(__('当前技能已经认证过了'));
- }
- $skillLevelInfo = \app\common\model\DispatchSkillLeaver::where(["skill_id"=>$skill_id])->find();
- $skillAreaInfo = \app\common\model\DispatchSkillArea::where(["skill_id"=>$skill_id])->find();
- $res = [];
- $res["level"] = $skillLevelInfo?1:0;
- $res["area"] = $skillAreaInfo?1:0;
- $this->success("没有认证过,可以去认证!", $res);
- }
-
- public function getReciveList() {
- $skill_id = $this->request->request('skill_id',0,"intval");
- $is_recommend = $this->request->request('is_recommend');
- $gender = $this->request->request('gender',-1);
- $page = $this->request->request('page',1);
- $pageNum = $this->request->request('pageNum',10);
-
- $pageStart = ($page-1)*$pageNum;
- if(!in_array($gender,[-1,0,1])) {
- $gender = -1;
- }
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- if ($skill_id > 0) {
- $where["a.skill_id"] = $skill_id;
- } else if($is_recommend == 1) {
- $where["a.is_recommend"] = $is_recommend;
- $where["a.is_main"] = 1;
- }
- $where["a.status"] = 1;
- $gender == -1 || $where["u.gender"] = $gender;
- $authList = $authModel->alias("a")
- ->field("a.id,u.avatar,ds.name as skill_name,a.voice,a.voice_time,a.price,ds.unit,u.nickname,u.gender")
- ->join("hx_user u","u.id = a.user_id")
- ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
- ->limit($pageStart,$pageNum)
- ->where($where)
- ->select();
- $this->success('获取成功!',$authList);
- }
-
- public function getReciveCommentList() {
- $page = $this->request->request('page',1);
- $pageNum = $this->request->request('pageNum',10);
-
- $pageStart = ($page-1)*$pageNum;
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- $where["a.is_main"] = 1;
- $where["a.status"] = 1;
- $where["a.is_recommend"] = 1;
- $authList = $authModel->alias("a")
- ->field("a.id,u.avatar,ds.name as skill_name,a.voice,a.voice_time,a.price,ds.unit,u.nickname,u.gender")
- ->join("hx_user u","u.id = a.user_id")
- ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
- ->limit($pageStart,$pageNum)
- ->where($where)
- ->select();
- $this->success('获取成功!',$authList);
- }
-
- public function getReciveInfo() {
- $auth_id = $this->request->request('auth_id',0,"intval");
- if (!$auth_id) {
- $this->error(__('Invalid parameters'));
- }
-
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- $where["a.id"] = $auth_id;
- $authInfo = $authModel->alias("a")
- ->field("a.id,a.user_id,a.image,a.voice,a.voice_time,u.avatar,u.nickname,u.u_id,u.is_online,s.id as skill_id,s.name as skill_name,s.image as skill_icon, a.price,s.unit,a.remarks")
- ->join("hx_user u","u.id = a.user_id")
- ->join("hx_dispatch_skill s","s.id = a.skill_id")
- ->where($where)
- ->find();
- if(!$authInfo) {
- $this->error(__('数据为空!'));
- }
-
- $where = [];
- $where["recive_id"] = $authInfo["user_id"];
- $where["status"] = 3;
- $authInfo["service_num"] = \app\common\model\DispatchOrder::where($where)->count();
-
- $viewuserskillModel = new \app\common\model\ViewUserSkill();
- $skillArr = $viewuserskillModel->getSkillInfoId($authInfo["user_id"]);
-
- $followid = \app\common\model\UserFansFollow::where(["fans_id"=>$this->auth->id,"user_id"=>$authInfo["user_id"]])->value("id");
- $authInfo["is_follow"] = $followid>0?1:0;
- $authInfo["skills"] = $skillArr;
- $this->success('获取成功!',$authInfo);
- }
-
- public function addOrder() {
- $user_id = $this->request->request('user_id',0,"intval");
- $skill_id = $this->request->request('skill_id',0,"intval");
- $num = $this->request->request('num',0,"intval");
- $make_time = $this->request->request('make_time');
- $describe = $this->request->request('describe');
- $makeTimeLen = strlen($make_time);
- if (!empty($make_time) && $makeTimeLen > 10) {
- $make_time = substr($make_time,0,10);
- }
- if (!$skill_id || !$num) {
- $this->error(__('Invalid parameters'));
- }
- $orderModel = new \app\common\model\DispatchOrder();
-
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- $where["user_id"] = $user_id;
- $where["skill_id"] = $skill_id;
- $where["status"] = 1;
- $authInfo = $authModel->where($where)->find();
- if(!$authInfo) {
- $this->error(__('技能认证信息不存在,或认证未通过!'),[],103);
- }
-
- $skillModel = new \app\common\model\DispatchSkill();
- $where = [];
- $where["id"] = $skill_id;
- $skillInfo = $skillModel->where($where)->find();
- if(!$skillInfo) {
- $this->error(__('技能信息未找到,请稍后重试!'));
- }
-
- $userModel = new \app\common\model\User();
- $where = [];
- $where["id"] = $this->auth->id;
- $jewel = $userModel->where($where)->value("jewel");
- $price = 0;
- $authInfo["price"] >= 0 || $price = 0;
- $authInfo["price"] >= 0 && $price = $authInfo["price"];
- $money = $price * $num;
- if($money > $jewel) {
- $this->error(__('钻石余额不足,请先充值!'),[],100);
- }
-
- if($this->auth->id == $authInfo["user_id"]) {
- $this->error(__('禁止自己下单!'),[],101);
- }
-
- $where = [];
- $where["user_id"] = $this->auth->id;
- $where["status"] = 0;
- $orderInfo = $orderModel->where($where)->find();
- Db::startTrans();
- try{
-
- $out_trade_no = date("YmdHis").rand(100000,999999);
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["order_no"] = $out_trade_no;
- $data["recive_id"] = $authInfo["user_id"];
- $data["auth_id"] = $authInfo["id"];
- $data["price"] = $authInfo["price"];
- $data["num"] = $num;
- $data["skill_image"] = $skillInfo["image"];
- $data["skill_name"] = $skillInfo["name"];
- $data["skill_unit"] = $skillInfo["unit"];
- $data["make_time"] = $make_time;
- $data["describe"] = $describe;
- $data["status"] = 0;
- $data["createtime"] = time();
- $res = $orderModel->insertGetId($data);
- if($res) {
- Db::commit();
- $this->success('订单创建成功!',["order_no"=>$out_trade_no]);
- } else {
- $this->error(__('订单创建失败!'));
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
-
- public function addOrderComment() {
- $order_no = $this->request->request('order_no');
- $content = $this->request->request('content');
- if (!$order_no && !$content) {
- $this->error(__('Invalid parameters'));
- }
- Db::startTrans();
- try{
- $ordercommentModel = new \app\common\model\DispatchOrderComment();
- $orderModel = new \app\common\model\DispatchOrder();
- $orderInfo = $orderModel->where(["order_no"=>$order_no])->find();
- if(!$orderInfo) $this->error(__('未查询到订单信息!'));
- if($orderInfo["status"] != 3) $this->error(__('当前订单状态不允许评价!'));
- $data= [];
- $data["user_id"] = $this->auth->id;
- $data["order_id"] = $orderInfo["id"];
- $data["content"] = $content;
- $data["createtime"] = time();
- $res1 = $ordercommentModel->insert($data);
- $res2 = $orderModel->update(["is_comment"=>1],["order_no"=>$order_no]);
- if($res1 && $res2) {
- Db::commit();
- $this->success('评价成功!');
- } else {
- $this->error(__('订单创建失败!'));
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
-
- public function jewelPay() {
- $order_no = $this->request->request('order_no');
- if (!$order_no) {
- $this->error(__('Invalid parameters'));
- }
-
- $orderModel = new \app\common\model\DispatchOrder();
- $where = [];
- $where["order_no"] = $order_no;
- $orderInfo = $orderModel->where($where)->find();
- if(!$orderInfo) {
- $this->error(__('订单信息获取失败!'));
- }
- if($orderInfo["status"] != 0) {
- $this->error(__('订单状态有误!'),[],104);
- }
-
- $userModel = new \app\common\model\User();
- $where = [];
- $where["id"] = $this->auth->id;
- $jewel = $userModel->where($where)->value("jewel");
- $money = $orderInfo["price"] * $orderInfo["num"];
- if($money > $jewel) {
- $this->error(__('钻石余额不足,请先充值!'),[],100);
- }
-
- Db::startTrans();
- try{
-
- $where = [];
- $where["id"] = $this->auth->id;
- $userInfo = $userModel->where($where)->find();
- $res1 = $userModel->where($where)->setDec("jewel",$money);
- $res2 = $userModel->where($where)->setInc("frozen",$money);
-
- $userjewellogModel = new \app\common\model\UserJewelLog();
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["value"] = $money;
- $data["mode"] = "-";
- $data["before"] = $userInfo["jewel"];
- $data["balance"] = $userInfo["jewel"]-$money;
- $data["detail"] = "下单扣除余额";
- $data["createtime"] = time();
- $res3 = $userjewellogModel->insertGetId($data);
-
- $orderModel = new \app\common\model\DispatchOrder();
-
- $where = [];
- $where["order_no"] = $order_no;
- $data = [];
- $data["status"] = 1;
- $res4 = $orderModel->update($data,$where);
- if($res1 && $res2 && $res3 && $res4) {
- Db::commit();
-
- $reciveuserInfo = $userModel->where(["id"=>$orderInfo["recive_id"]])->find();
-
-
- \app\common\model\Message::addMessage($orderInfo["recive_id"],"派单通知","您的派单,技能:".$orderInfo["skill_name"]."有人接单啦,请登录伴声app查看!");
- $this->success('支付成功!');
- } else {
- $this->error(__('订单创建失败!'));
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
-
- public function changeOrder() {
- $order_no = $this->request->request('order_no');
- $status = $this->request->request('status');
- if (!$order_no || !$status) {
- $this->error(__('Invalid parameters'));
- }
- if(!in_array($status,["-2","-1","2","3"])) {
- $this->error("非法的订单状态参数");
- }
-
- $orderModel = new \app\common\model\DispatchOrder();
- $where = [];
- $where["order_no"] = $order_no;
- $orderInfo = $orderModel->where($where)->find();
- if(!$orderInfo) {
- $this->error(__('订单信息获取失败!'));
- }
- if($orderInfo["status"] == $status) {
- $this->error(__('当前订单状态无变更要求!'),[],104);
- }
-
- if($status == -1 && $orderInfo["recive_id"] != $this->auth->id) {
- $this->error(__('无权限操作!'),[],103);
- }
-
- if(($status == -2 || $status == 3) && $orderInfo["user_id"] != $this->auth->id) {
- $this->error(__('无权限操作!'),[],103);
- }
- if($status == -1) {
- if($orderInfo["status"] != 1) {
- $this->error(__('当前订单状态不支持拒绝订单!'),[],104);
- }
-
- Db::startTrans();
- try{
- $userModel = new \app\common\model\User();
- $money = $orderInfo["price"] * $orderInfo["num"];
-
- $where = [];
- $where["id"] = $this->auth->id;
- $userInfo = $userModel->where($where)->find();
- if($userInfo["frozen"] - $money < 0) {
- $this->error(__('账户资金异常,请联系管理员!'),[],105);
- }
- $res1 = $userModel->where($where)->setDec("frozen",$money);
- $res2 = $userModel->where($where)->setInc("jewel",$money);
-
- $userjewellogModel = new \app\common\model\UserJewelLog();
- $res3 = $userjewellogModel->addUserJewelLog($this->auth->id, $money, "+", $userInfo["jewel"], "拒绝订单返还余额", 7);
-
- $data = [];
- $data["status"] = $status;
- $where = [];
- $where["order_no"] = $order_no;
- $res4 = $orderModel->update($data,$where);
- if($res1 && $res2 && $res3 && $res4) {
- Db::commit();
-
- $reciveuserInfo = $userModel->where(["id"=>$orderInfo["user_id"]])->find();
-
-
- \app\common\model\Message::addMessage($orderInfo["user_id"],"派单通知","您的订单,技能:".$orderInfo["skill_name"]."已被拒绝接单,请登录伴声app查看!");
- $this->success('订单完成。');
- } else {
- $this->error(__('订单更新失败!请稍后重试'));
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- } elseif($status == 3) {
- if($orderInfo["status"] != 2) {
- $this->error(__('当前订单状态不支持直接变更为已完成!'),[],104);
- }
-
- Db::startTrans();
- try{
- $userModel = new \app\common\model\User();
- $money = $orderInfo["price"] * $orderInfo["num"];
-
- $where = [];
- $where["id"] = $orderInfo["recive_id"];
- $userInfo = $userModel->where($where)->find();
- $res1 = $userModel->where($where)->setInc("jewel",$money);
- $where = [];
- $where["id"] = $this->auth->id;
- $res2 = $userModel->where($where)->setDec("frozen",$money);
-
- $userjewellogModel = new \app\common\model\UserJewelLog();
- $res3 = $userjewellogModel->addUserJewelLog($orderInfo["recive_id"], $money, "+", $userInfo["jewel"], "完成用户订单获得收益", 8);
-
- $data = [];
- $data["status"] = $status;
- $where = [];
- $where["order_no"] = $order_no;
- $res4 = $orderModel->update($data,$where);
- if($res1 && $res2 && $res3 && $res4) {
- Db::commit();
-
- $reciveuserInfo = $userModel->where(["id"=>$orderInfo["recive_id"]])->find();
-
-
- \app\common\model\Message::addMessage($orderInfo["recive_id"],"派单通知","您的派单,技能:".$orderInfo["skill_name"]." 完成啦!,请登录伴声app查看!");
- $this->success('恭喜!订单完成。');
- } else {
- $this->error(__('订单更新失败!请稍后重试'));
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- } else {
- $data = [];
- $data["status"] = $status;
- $where = [];
- $where["order_no"] = $order_no;
- $res = $orderModel->update($data,$where);
- if($res) {
- $this->success('更新成功!');
- } else {
- $this->error(__('订单创建失败!'));
- }
- }
- }
-
- public function getSkillList() {
- $skillModel = new \app\common\model\DispatchSkill();
- $skillList = $skillModel->select();
- if ($skillList) {
- $this->success(__('获取成功!'), $skillList);
- } else {
- $this->success(__('数据为空!'));
- }
- }
-
- public function getSkillLevelList() {
- $skill_id = $this->request->request('skill_id');
- if (!$skill_id) {
- $this->error(__('Invalid parameters'));
- }
- $skilllevelModel = new \app\common\model\DispatchSkillLeaver();
- $where = [];
- $where["skill_id"] = $skill_id;
- $skilllevelList = $skilllevelModel->where($where)->select();
- if ($skilllevelList) {
- $this->success(__('获取成功!'), $skilllevelList);
- } else {
- $this->success(__('数据为空!'));
- }
- }
-
- public function getSkillAreaList() {
- $skill_id = $this->request->request('skill_id');
- if (!$skill_id) {
- $this->error(__('Invalid parameters'));
- }
- $skillareaModel = new \app\common\model\DispatchSkillArea();
- $where = [];
- $where["skill_id"] = $skill_id;
- $skillareaList = $skillareaModel->where($where)->select();
- if ($skillareaList) {
- $this->success(__('获取成功!'), $skillareaList);
- } else {
- $this->success(__('数据为空!'));
- }
- }
-
- public function getOrderList() {
- $type = $this->request->request('type',1);
- $status = $this->request->request('status',999);
- $page = $this->request->request('page',1);
- $pageNum = $this->request->request('pageNum',10);
-
- $pageStart = ($page-1)*$pageNum;
- $user = "o.recive_id";
- $type == 1 && $user = "o.recive_id";
- $type == 2 && $user = "o.user_id";
-
- $orderModel = new \app\common\model\DispatchOrder();
- $where = [];
- $type == 1 && $where["o.user_id"] = $this->auth->id;
- $type == 2 && $where["o.recive_id"] = $this->auth->id;
- $status != 999 && $where["o.status"] = $status;
- $orderList = $orderModel->alias("o")
- ->field("o.id,".$user." as user_id,o.make_time,o.describe,o.order_no,u.avatar,u.nickname,o.skill_image,o.skill_name,o.price,o.skill_unit,o.num,o.status,o.is_comment,o.createtime")
- ->join("hx_user u","u.id = ".$user)
- ->where($where)
- ->order("createtime","desc")
- ->limit($pageStart,$pageNum)
- ->select();
- if(!$orderList) {
- $this->success(__('数据为空!'),[]);
- }
- foreach($orderList as $k => &$v) {
- $v["make_time"] = date("Y-m-d H:i",$v["make_time"]);
- $v["createtime"] = date("Y-m-d",$v["createtime"]);
- $v["status_text"] = $orderModel->getStateAttr($v["status"]);
- }
- $this->success(__('获取成功!'), $orderList);
- }
- }
|