0 ? 'OSP' . time() : 'OAP' . time(); $order = $this->where('no', $no)->find(); if (!$order) $check = false; } return $no; } public function getPaymentTypeList() { return ['ali' => __('Ali'), 'wechat' => __('Wechat'), 'balance' => __('Balance')]; } public function getStatusList() { return ['proceed' => __('Proceed'), 'pending' => __('Pending'), 'finish' => __('Finish'), 'wait_feedback' => __('Wait_feedback'), 'cancel' => __('Cancel')]; } public function user() { return $this->hasOne(User::class, "id", "user_id", [], "LEFT")->setEagerlyType(0); } public function area() { return $this->belongsTo(Area::class, 'user_area_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function store() { return $this->belongsTo(Store::class, 'store_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function massager() { return $this->belongsTo(Massager::class, 'massager_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function services() { return $this->hasMany(Service::class, 'order_id', 'id'); } public function progress() { return $this->hasMany(Progress::class, 'order_id', 'id')->order("index", "asc"); } public function bill() { return $this->belongsTo(Bill::class, 'no', 'order_no', [], 'LEFT')->setEagerlyType(0); } public function comment() { return $this->belongsTo(Comment::class, 'id', 'order_id', [], 'LEFT')->setEagerlyType(0); } public function order_detail($order_id) { return $this->where([ "order.id" => $order_id ])->with(["area", "store", "massager", "services", "progress"]) ->find(); } /** * @param $user_id * @param $status * @param $page * @param $size * @return \think\Paginator * @throws \think\exception\DbException */ public function fetchOrder($user_id, array $status, $page, $size) { return $this->where(["order.user_id" => $user_id]) ->where("order.status", "in", $status) ->where("order.is_delete", 0) ->with(["services", "massager"]) ->order("order.updatetime", "desc") ->page($page) ->paginate($size); } public function fetchByJudgeMassagerWork($massager_id, $order_id) { return $this->where("massager_id", $massager_id) ->where("id", "<>", $order_id) ->where('service_start_date', '>=', date('Y-m-d H:00:00', time())) ->where('service_start_date', '<=', date('Y-m-d H:00:00', time() + 2 * 24 * 60 * 60)) ->where('status', 'in', [ \E_ORDER_STATUS::Purchase, \E_ORDER_STATUS::Proceed, ]) ->select(); } public function fetchMassagerOrder($m_id, array $status, $page, $size) { return $this->alias("o") ->where(["o.massager_id" => $m_id]) ->where("o.status", "in", $status) ->with("services") ->order("o.updatetime", "desc") ->page($page) ->paginate($size); } public function untakeOrderCount($m_id) { return $this->where([ "massager_id" => $m_id, "status" => \E_ORDER_STATUS::Purchase ])->count(); } public function sumTotalServiceAmount($m_id) { return $this->where("massager_id", $m_id) ->where("status", "in", [ \E_ORDER_STATUS::Proceed, \E_ORDER_STATUS::Purchase, \E_ORDER_STATUS::WaitFeedback, \E_ORDER_STATUS::Finish ])->where("is_use_profit", 0) ->sum("total_service_amount"); } public function fetchByTripAmountGTZero($m_id, $page, $size) { return $this->where([ "massager_id" => $m_id, "status" => \E_ORDER_STATUS::Finish ]) ->order("updatetime", "desc") ->page($page) ->paginate($size); } public function groupByMassager($id, $starttime, $endtime) { return $this->where("massager_id", $id) ->where('createtime', 'between time', [$starttime, $endtime]) ->field('createtime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(createtime), "%Y-%m-%d") AS create_date') ->group('create_date') ->select(); } function sumPerformanceByIntraday($m_id, $city_code, $intraday) { if (is_null($intraday)) { $intraday = date("Y-m-d"); } else { $intraday = date("Y-m-d", strtotime($intraday)); } $total_real_amount = $this->where("massager_id", $m_id) ->where("city_code", $city_code) ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m-%d') = '{$intraday}'") ->where("status", \E_ORDER_STATUS::Finish) ->sum("total_real_amount"); $total_trip_amount = $this->where("massager_id", $m_id) ->where("city_code", $city_code) ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m-%d') = '{$intraday}'") ->where("status", \E_ORDER_STATUS::Finish) ->sum("trip_amount"); return $total_real_amount - $total_trip_amount; } function sumPerformanceByNowMonth($m_id, $city_code, $y = null, $m = null) { $ym_str = ym($y, $m); $total_real_amount = $this->where("massager_id", $m_id) ->where("city_code", $city_code) ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m') = '{$ym_str}'") ->where("status", \E_ORDER_STATUS::Finish) ->sum("total_real_amount"); $total_trip_amount = $this->where("massager_id", $m_id) ->where("city_code", $city_code) ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m') = '{$ym_str}'") ->where("status", \E_ORDER_STATUS::Finish) ->sum("trip_amount"); return $total_real_amount - $total_trip_amount; } function countByPraiseRate($m_id, $city_code, $year = null, $month = null) { $ym_str = ym($year, $month); $all = $this ->with("comment") ->where("order.city_code", $city_code) ->where("order.massager_id", $m_id) ->where("DATE_FORMAT(FROM_UNIXTIME(order.createtime),'%Y-%m') = '{$ym_str}'") ->where("order.status", \E_ORDER_STATUS::Finish) ->select(); $count = count($all); if (0 === $count) return 0; $praiseCount = array_reduce($all, function ($p, $cur) { if ($cur["comment"]["negative"] == 0) $p += 1; return $p; }, 0); return $praiseCount > 0 ? fixed2Float(($praiseCount / $count) * 100) : 0; } function chargebackRate($m_id, $city_code, $year = null, $month = null) { $ym_str = ym($year, $month); $total = $this ->with("comment") ->where("order.city_code", $city_code) ->where("order.massager_id", $m_id) ->where("DATE_FORMAT(FROM_UNIXTIME(order.createtime),'%Y-%m') = '{$ym_str}'") ->where("order.status", "in", [ \E_ORDER_STATUS::Proceed, \E_ORDER_STATUS::WaitFeedback, \E_ORDER_STATUS::Finish, \E_ORDER_STATUS::Reject, \E_ORDER_STATUS::Cancel, \E_ORDER_STATUS::AdminCancel, \E_ORDER_STATUS::AutoCancel ]) ->count(); $chargeback = $this ->with("comment") ->where("order.city_code", $city_code) ->where("order.massager_id", $m_id) ->where("DATE_FORMAT(FROM_UNIXTIME(order.createtime),'%Y-%m') = '{$ym_str}'") ->where("order.status", "in", [ \E_ORDER_STATUS::Reject, \E_ORDER_STATUS::AutoCancel ]) ->count(); return $chargeback > 0 ? fixed2Float(($chargeback / $total) * 100) : 0; } function reorderRateByNowMonth($m_id, $city_code, $year = null, $month = null) { $ym_str = ym($year, $month); $all = $this ->where("city_code", $city_code) ->where("massager_id", $m_id) ->where("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m') = '$ym_str'") ->where("status", \E_ORDER_STATUS::Finish) ->select(); $count = count($all); if (0 === $count) return 0; $reorderCount = array_reduce($all, function ($p, $cur) { if ($cur["reorder"] == 1) $p += 1; return $p; }, 0); $count -= $reorderCount; if ($reorderCount > $count) return 100; return $reorderCount > 0 ? fixed2Float(($reorderCount / $count) * 100) : 0; } function monthFinishOrdersByYm($m_id, $city_code, $year = null, $month = null) { $ym_str = ym($year, $month); return $this->where("order.massager_id", $m_id) ->with("bill") ->where("order.city_code", $city_code) ->where("DATE_FORMAT(FROM_UNIXTIME(order.createtime),'%Y-%m') = '{$ym_str}'") ->where("order.status", \E_ORDER_STATUS::Finish) ->where([ "bill.identity_type" => \E_IDENTITY_TYPE::Massager, "bill.target_id" => $m_id, "bill.change_type" => "profit", ]) ->order("createtime", "DESC") ->select(); } /** * @param $user_id * @return int|string * @throws \think\Exception */ static function countByUser($user_id) { return self::where([ "user_id" => $user_id, "status" => \E_ORDER_STATUS::Finish ])->count(); } /** * @param $user_id * @return bool|float|int|string|null */ static function sumByUser($user_id) { return self::where([ "user_id" => $user_id, "status" => \E_ORDER_STATUS::Finish ])->sum("total_real_amount"); } public function fetchByMassager($m_id, $y, $m) { $ym = ym($y, $m); return $this->where("DATE_FORMAT(FROM_UNIXTIME(pay_time),'%Y-%m') = '$ym'") ->where("massager_id", $m_id) ->where("status", \E_ORDER_STATUS::Finish) ->order("pay_time", "DESC") ->select(); } public function fetchReorderByMassager($m_id, $y, $m) { $ym = ym($y, $m); return $this->where("DATE_FORMAT(FROM_UNIXTIME(pay_time),'%Y-%m') = '$ym'") ->where("massager_id", $m_id) ->where("reorder", 1) ->where("status", \E_ORDER_STATUS::Finish) ->order("pay_time", "desc") ->select(); } public function byOrderCommentExpired($max_timeout) { return $this->where("updatetime", "<=", $max_timeout) ->where("status", \E_ORDER_STATUS::WaitFeedback) ->order("createtime", "ASC") ->select(); } public function byOrderTakeExpired($max_timeout) { return $this->where("pay_time", "<=", $max_timeout) ->where("massager_id", ">", 0) ->where("status", \E_ORDER_STATUS::Purchase) ->order("createtime", "ASC") ->select(); } }