|
|
@@ -11,8 +11,12 @@
|
|
|
|
|
|
namespace App\Services\Common;
|
|
|
|
|
|
+use App\Models\GoodsModel;
|
|
|
+use App\Models\MemberModel;
|
|
|
use App\Models\OrderModel;
|
|
|
+use App\Models\ScoreGoodsModel;
|
|
|
use App\Services\BaseService;
|
|
|
+use App\Services\ConfigService;
|
|
|
|
|
|
/**
|
|
|
* 积分商城订单管理-服务类
|
|
|
@@ -75,7 +79,7 @@ class OrderService extends BaseService
|
|
|
$list = $this->model->from('orders as a')
|
|
|
->leftJoin('member as b', 'a.user_id', '=', 'b.id')
|
|
|
->leftJoin('score_goods as g', 'g.id', '=', 'a.goods_id')
|
|
|
- ->leftJoin('score_goods_cate as c', 'c.id', '=', 'a.cate_id')
|
|
|
+ ->leftJoin('score_goods_cate as c', 'c.id', '=', 'g.cate_id')
|
|
|
->where($where)
|
|
|
->where(function ($query) use ($params) {
|
|
|
$keyword = isset($params['keyword']) ? $params['keyword'] : '';
|
|
|
@@ -84,7 +88,6 @@ class OrderService extends BaseService
|
|
|
}
|
|
|
})
|
|
|
->where(function ($query) use ($userId) {
|
|
|
-
|
|
|
if($userId){
|
|
|
$query->where('a.user_id', '=', $userId);
|
|
|
}
|
|
|
@@ -139,4 +142,187 @@ class OrderService extends BaseService
|
|
|
})
|
|
|
->count('id');
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getInfo($id)
|
|
|
+ {
|
|
|
+ $info = $this->model->from('orders as a')
|
|
|
+ ->leftJoin('member as b', 'a.user_id', '=', 'b.id')
|
|
|
+ ->leftJoin('score_goods as g', 'g.id', '=', 'a.goods_id')
|
|
|
+ ->where(['a.id'=>$id,'a.mark'=>1])
|
|
|
+ ->select(['a.*', 'b.nickname', 'b.mobile as buy_mobile', 'g.goods_name','g.source_price', 'g.code', 'g.thumb'])
|
|
|
+ ->first();
|
|
|
+ if($info){
|
|
|
+ $info['create_time_text'] = $info['create_time'] ? datetime($info['create_time'], 'Y-m-d H:i:s') : '';
|
|
|
+ $info['pay_time'] = $info['pay_time'] ? datetime($info['pay_time'], 'Y-m-d H:i:s') : '';
|
|
|
+ $info['thumb'] = isset($info['thumb']) && $info['thumb'] ? get_image_url($info['thumb']) : '';
|
|
|
+ $info['pay_img'] = isset($info['pay_img']) && $info['pay_img'] ? get_image_url($info['pay_img']) : '';
|
|
|
+
|
|
|
+ $address = MemberAddressService::make()->getBindInfo($info['user_id']);
|
|
|
+ $info['address'] = $address? $address : [];
|
|
|
+
|
|
|
+ // 积分
|
|
|
+ $scoreRate = MemberModel::where(['id'=> $info['user_id']])->value('score_rate');
|
|
|
+ $scoreRate = $scoreRate>0 && $scoreRate<=1? $scoreRate : 1;
|
|
|
+ $info['score'] = round($info['total']/$scoreRate, 0);
|
|
|
+
|
|
|
+ $bankInfo = ConfigService::make()->getConfigByGroupValue('8');
|
|
|
+ $info['bank_info'] = $bankInfo? $bankInfo : ['realname'=>'','bank_name'=>'','bank_num'=>''];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 兑换
|
|
|
+ * @param $userId
|
|
|
+ */
|
|
|
+ public function exchange($userId, $shopId)
|
|
|
+ {
|
|
|
+ $params = request()->all();
|
|
|
+ $goodsId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $info = ScoreGoodsModel::where(['id'=> $goodsId,'mark'=>1,'status'=>1])->first();
|
|
|
+ if(empty($info)){
|
|
|
+ $this->error = 2061;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $userId,'mark'=>1,'status'=>1])->select(['id','member_level','nickname'])->first();
|
|
|
+ $memberLevel = isset($memberInfo['member_level'])? $memberInfo['member_level'] : 0;
|
|
|
+ if(empty($memberInfo)){
|
|
|
+ $this->error = 2019;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $total = $memberLevel? $info['price'] : $info['source_price'];
|
|
|
+ $order = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'shop_id'=> $shopId,
|
|
|
+ 'goods_id'=> $goodsId,
|
|
|
+ 'order_sn'=> get_order_num('S'),
|
|
|
+ 'price'=> $info['price'],
|
|
|
+ 'num'=> 1,
|
|
|
+ 'total'=> $total,
|
|
|
+ 'pay_money'=> $total,
|
|
|
+ 'status'=>1,
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'mark'=>1
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $this->model->insertGetId($order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付兑换
|
|
|
+ * @param $userId
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function pay($userId)
|
|
|
+ {
|
|
|
+ $params = request()->all();
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $info = $this->model->where(['id'=> $id,'mark'=>1,'status'=>1])->first();
|
|
|
+ $total = isset($info['total'])? $info['total'] : 0;
|
|
|
+ if(!$id || empty($info)){
|
|
|
+ $this->error = 2073;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $payScore = isset($params['score'])? intval($params['score']) : 0;
|
|
|
+ $addressInfo = isset($params['address'])? $params['address'] : [];
|
|
|
+ $payImg = isset($params['pay_img'])? $params['pay_img'] : '';
|
|
|
+ if(empty($addressInfo)){
|
|
|
+ $this->error = 2075;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($payScore<=0 && empty($payImg)){
|
|
|
+ $this->error = 2074;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $userId,'mark'=>1,'status'=>1])->first();
|
|
|
+ $score = isset($memberInfo['score'])? $memberInfo['score'] : 0;
|
|
|
+ $scoreRate = isset($memberInfo['score_rate'])? $memberInfo['score_rate'] : 0;
|
|
|
+ $scoreRate = $scoreRate>0 && $scoreRate<=1? $scoreRate : 1;
|
|
|
+ if(empty($memberInfo)){
|
|
|
+ $this->error = 2019;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($payScore > $score){
|
|
|
+ $this->error = 2077;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 所需积分
|
|
|
+ $needScore = round($total/$scoreRate, 0);
|
|
|
+ if($payScore<$needScore && empty($payImg)){
|
|
|
+ $this->error = 2076;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $scorePayMoney = intval($payScore*$scoreRate, 0);
|
|
|
+ $payMoney = round($total - $scorePayMoney, 0);
|
|
|
+
|
|
|
+ $address = [];
|
|
|
+ $address[] = isset($addressInfo['province'])? $addressInfo['province'] : '';
|
|
|
+ $address[] = isset($addressInfo['city'])? $addressInfo['city'] : '';
|
|
|
+ $address[] = isset($addressInfo['district'])? $addressInfo['district'] : '';
|
|
|
+ $address[] = isset($addressInfo['address'])? $addressInfo['address'] : '';
|
|
|
+ $address = array_filter($address);
|
|
|
+ $data = [
|
|
|
+ 'pay_img'=> $payImg,
|
|
|
+ 'pay_time'=> time(),
|
|
|
+ 'user_address'=> $address? implode(' ', $address) : '',
|
|
|
+ 'realname'=> isset($addressInfo['realname'])? $addressInfo['realname'] : '',
|
|
|
+ 'user_mobile'=> isset($addressInfo['mobile'])? $addressInfo['mobile'] : '',
|
|
|
+ 'pay_score'=> $payScore,
|
|
|
+ 'pay_money'=> $payMoney,
|
|
|
+ 'status'=> 2,
|
|
|
+ 'update_time'=>time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($this->model->where(['id'=> $id])->update($data)){
|
|
|
+ $this->error = 2078;
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ $this->error = 2079;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function receive()
|
|
|
+ {
|
|
|
+ $params = request()->all();
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $info = $this->model->where(['id'=> $id,'mark'=>1])->first();
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ if(!$id || empty($info)){
|
|
|
+ $this->error = 2081;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!in_array($status, [3,4,5])){
|
|
|
+ $this->error = 2082;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->model->where(['id'=> $id])->update(['status'=> 5, 'update_time'=> time()])){
|
|
|
+ $this->error = 2083;
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ $this->error = 2084;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|