|
@@ -2,19 +2,14 @@
|
|
|
|
|
|
namespace app\mainapp\controller;
|
|
|
|
|
|
-use think\facade\Session;
|
|
|
use app\mainapp\BaseController;
|
|
|
|
|
|
-use app\common\model\User as UserModel;
|
|
|
use app\common\model\Demand as DemandModel;
|
|
|
use app\common\model\DemandCate as DemandCateModel;
|
|
|
use app\common\model\DemandLog as DemandLogModel;
|
|
|
use app\common\model\Param as ParamModel;
|
|
|
-use app\common\model\Worker as WorkerModel;
|
|
|
use app\common\model\WorkerLog as WorkerLogModel;
|
|
|
-use app\common\model\UserIntegral as UserIntegralModel;
|
|
|
-
|
|
|
-use echowx\WxProgram;
|
|
|
+use app\common\model\DemandSnatch as DemandSnatchModel;
|
|
|
|
|
|
class Demand extends BaseController
|
|
|
{
|
|
@@ -108,7 +103,7 @@ class Demand extends BaseController
|
|
|
$map[] = ['district', '=', $district];
|
|
|
}
|
|
|
$orderby = ['status' => 'asc', 'updatetime' => 'desc', 'id' => 'desc'];
|
|
|
- $plist = DemandModel::with(['worker', 'demandCate'])->where($map)->order($orderby)->page($ppage)->limit($psize)->append(['ftype_text','type_text'])->select();
|
|
|
+ $plist = DemandModel::with(['worker', 'demandCate'])->where($map)->order($orderby)->page($ppage)->limit($psize)->append(['ftype_text', 'type_text'])->select();
|
|
|
page_result(0, "", [
|
|
|
'plist' => $plist,
|
|
|
'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
|
|
@@ -119,7 +114,7 @@ class Demand extends BaseController
|
|
|
public function getDemand()
|
|
|
{
|
|
|
$demandid = input('demandid/d', 0);
|
|
|
- $demand = DemandModel::with(['worker'])->where('status', 'in', '3,4')->where('id', '=', $demandid)->append(['ftype_text','type_text'])->findOrEmpty();
|
|
|
+ $demand = DemandModel::with(['worker'])->where('status', 'in', '3,4')->where('id', '=', $demandid)->append(['ftype_text', 'type_text'])->findOrEmpty();
|
|
|
if ($demand->isEmpty()) {
|
|
|
page_result(1, "订单信息不存在。");
|
|
|
}
|
|
@@ -173,65 +168,133 @@ class Demand extends BaseController
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- public function setDemandLog()
|
|
|
+ public function demandSnatch()
|
|
|
{
|
|
|
- $demandid = input('demandid/d', 0);
|
|
|
- $demand = DemandModel::findOrEmpty($demandid);
|
|
|
- if ($demand->isEmpty()) {
|
|
|
- page_result(1, "订单信息不存在");
|
|
|
+ $id = input('id/d', 0);
|
|
|
+ if (empty($id)) {
|
|
|
+ page_result(1, "未查询到数据。");
|
|
|
}
|
|
|
- if (strtotime($demand->enddate) + 86400 < time()) {
|
|
|
- page_result(1, "该订单信息接单已截止,不能再接单了。");
|
|
|
+
|
|
|
+ //数据校验
|
|
|
+ $num = input('num/d', 0);
|
|
|
+ $workerid = input('workerid/d', 0);
|
|
|
+ if ($num <= 0) {
|
|
|
+ page_result(1, "抢单人数必须大于0。");
|
|
|
}
|
|
|
- $gworkerid = input('gworkerid/d', 0);
|
|
|
- $worker = WorkerModel::findOrEmpty($gworkerid);
|
|
|
- if ($worker->isEmpty()) {
|
|
|
- page_result(1, "劳务企业信息不存在");
|
|
|
+ if (empty($workerid)) {
|
|
|
+ page_result(1, "登录信息异常,请重新登录。");
|
|
|
}
|
|
|
- $log = DemandLogModel::where(['demandid' => $demandid, 'gworkerid' => $gworkerid])->findOrEmpty();
|
|
|
- if ($log->isEmpty()) {
|
|
|
- $log = new DemandLogModel;
|
|
|
- $log->save([
|
|
|
- 'workerid' => $demand->workerid,
|
|
|
- 'demandid' => $demandid,
|
|
|
- 'gworkerid' => $gworkerid,
|
|
|
- 'createtime' => time(),
|
|
|
- ]);
|
|
|
- $userid = input('userid/d', 0);
|
|
|
- $user = UserModel::where(1)->findOrEmpty($userid);
|
|
|
- $param = ParamModel::where(1)->findOrEmpty();
|
|
|
- if ($user->integral < $param->teldemand) {
|
|
|
- page_result(1, "接单&咨询该订单会扣除" . $param->teldemand . "积分,你当前积分不足。");
|
|
|
- }
|
|
|
- $intdata = [
|
|
|
- 'userid' => $userid,
|
|
|
- 'title' => "接单&咨询订单信息扣除",
|
|
|
- 'intvalue' => 0 - $param->teldemand,
|
|
|
- 'intmoney' => 0.00,
|
|
|
- 'onlycontent' => "",
|
|
|
- 'remark' => $demand->title,
|
|
|
- 'itype' => 5,
|
|
|
- 'status' => 2,
|
|
|
- 'createtime' => date("Y-m-d H:i:s"),
|
|
|
- 'yeartime' => date("Y"),
|
|
|
- 'monthtime' => date("Ym"),
|
|
|
+ $demand = DemandModel::find($id);
|
|
|
+ if (empty($demand)) {
|
|
|
+ page_result(1, "订单不存在。");
|
|
|
+ }
|
|
|
+ $check = DemandSnatchModel::where('demand_id', $id)->where('worker_id', $workerid)->find();
|
|
|
+ if (!empty($check)) {
|
|
|
+ page_result(1, "请勿重复抢单。");
|
|
|
+ }
|
|
|
+ $total = DemandSnatchModel::where('status', '>', 1)->where('demand_id', $id)->sum('num');
|
|
|
+ $remain = $demand['num'] - $total;
|
|
|
+ if ($demand['num'] - $total < $num) {
|
|
|
+ page_result(1, "订单剩余{$remain}人,请输入该人数以下的值。");
|
|
|
+ }
|
|
|
+
|
|
|
+ //抢单
|
|
|
+ DemandSnatchModel::create([
|
|
|
+ 'demand_id' => $id,
|
|
|
+ 'worker_id' => $workerid,
|
|
|
+ 'num' => $num,
|
|
|
+ 'status' => 1,
|
|
|
+ 'createtime' => date("Y-m-d H:i:s"),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ page_result(0, "", []);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function listSnatch()
|
|
|
+ {
|
|
|
+ $ppage = input('ppage/d', 1);
|
|
|
+ $psize = input('psize/d', 20);
|
|
|
+ $workerid = input('workerid/d', 0);
|
|
|
+ $map[] = ['worker_id', '=', $workerid];
|
|
|
+ $status = input('status/d', 0);
|
|
|
+ if (!empty($status)) {
|
|
|
+ $map[] = [
|
|
|
+ ['status', '=', $status],
|
|
|
];
|
|
|
- UserIntegralModel::create($intdata);
|
|
|
- $integral = intval($user->integral) - intval($param->teldemand);
|
|
|
- $user->save([
|
|
|
- 'integral' => $integral,
|
|
|
- ]);
|
|
|
- $telearr = $demand->telearr;
|
|
|
- $telearr[] = $userid;
|
|
|
- $demand->save([
|
|
|
- 'telearr' => $telearr,
|
|
|
- ]);
|
|
|
- page_result(0, "", []);
|
|
|
- } else {
|
|
|
- page_result(1, "你已接单过了,无需重复接单。");
|
|
|
}
|
|
|
+ $plist = DemandSnatchModel::with(['demand', 'worker'])
|
|
|
+ ->where($map)
|
|
|
+ ->order(['createtime' => 'desc', 'id' => 'desc'])
|
|
|
+ ->page($ppage)
|
|
|
+ ->limit($psize)
|
|
|
+ ->append(['status_text', 'demand'=>['ftype_text','wtype_text']])
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ page_result(0, "", [
|
|
|
+ 'plist' => $plist,
|
|
|
+ 'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
+// public function setDemandLog()
|
|
|
+// {
|
|
|
+// $demandid = input('demandid/d', 0);
|
|
|
+// $demand = DemandModel::findOrEmpty($demandid);
|
|
|
+// if ($demand->isEmpty()) {
|
|
|
+// page_result(1, "订单信息不存在");
|
|
|
+// }
|
|
|
+// if (strtotime($demand->enddate) + 86400 < time()) {
|
|
|
+// page_result(1, "该订单信息接单已截止,不能再接单了。");
|
|
|
+// }
|
|
|
+// $gworkerid = input('gworkerid/d', 0);
|
|
|
+// $worker = WorkerModel::findOrEmpty($gworkerid);
|
|
|
+// if ($worker->isEmpty()) {
|
|
|
+// page_result(1, "劳务企业信息不存在");
|
|
|
+// }
|
|
|
+// $log = DemandLogModel::where(['demandid' => $demandid, 'gworkerid' => $gworkerid])->findOrEmpty();
|
|
|
+// if ($log->isEmpty()) {
|
|
|
+// $log = new DemandLogModel;
|
|
|
+// $log->save([
|
|
|
+// 'workerid' => $demand->workerid,
|
|
|
+// 'demandid' => $demandid,
|
|
|
+// 'gworkerid' => $gworkerid,
|
|
|
+// 'createtime' => time(),
|
|
|
+// ]);
|
|
|
+// $userid = input('userid/d', 0);
|
|
|
+// $user = UserModel::where(1)->findOrEmpty($userid);
|
|
|
+// $param = ParamModel::where(1)->findOrEmpty();
|
|
|
+// if ($user->integral < $param->teldemand) {
|
|
|
+// page_result(1, "接单&咨询该订单会扣除" . $param->teldemand . "积分,你当前积分不足。");
|
|
|
+// }
|
|
|
+// $intdata = [
|
|
|
+// 'userid' => $userid,
|
|
|
+// 'title' => "接单&咨询订单信息扣除",
|
|
|
+// 'intvalue' => 0 - $param->teldemand,
|
|
|
+// 'intmoney' => 0.00,
|
|
|
+// 'onlycontent' => "",
|
|
|
+// 'remark' => $demand->title,
|
|
|
+// 'itype' => 5,
|
|
|
+// 'status' => 2,
|
|
|
+// 'createtime' => date("Y-m-d H:i:s"),
|
|
|
+// 'yeartime' => date("Y"),
|
|
|
+// 'monthtime' => date("Ym"),
|
|
|
+// ];
|
|
|
+// UserIntegralModel::create($intdata);
|
|
|
+// $integral = intval($user->integral) - intval($param->teldemand);
|
|
|
+// $user->save([
|
|
|
+// 'integral' => $integral,
|
|
|
+// ]);
|
|
|
+// $telearr = $demand->telearr;
|
|
|
+// $telearr[] = $userid;
|
|
|
+// $demand->save([
|
|
|
+// 'telearr' => $telearr,
|
|
|
+// ]);
|
|
|
+// page_result(0, "", []);
|
|
|
+// } else {
|
|
|
+// page_result(1, "你已接单过了,无需重复接单。");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
// public function teleDemand()
|
|
|
// {
|
|
|
// $demandid = input('demandid/d', 0);
|