Commit 25836233 authored by 刘小敏's avatar 刘小敏

用户软删除优化,AI试戴每天上限5次接口,订单结算积分参与结算(未完结),AI试戴饰品列表接口

parent ab4c7407
...@@ -170,7 +170,25 @@ class Order extends Common ...@@ -170,7 +170,25 @@ class Order extends Common
$this->success('获取成功', $result); $this->success('获取成功', $result);
} }
/**
* 获取用户可用积分余额
*
* @param Request $request
* @return void
*/
public function scores()
{
if (!$this->request->isPost()) {
$this->error('');
}
$params = $this->request->param();
$this->svalidate($params, ".create");
$orderCreate = new OrderCreate($params);
$result = $orderCreate->getScores();
$this->success('获取成功', $result);
}
// 取消订单 // 取消订单
public function cancel() public function cancel()
......
...@@ -4,7 +4,11 @@ namespace addons\shopro\controller\user; ...@@ -4,7 +4,11 @@ namespace addons\shopro\controller\user;
use addons\shopro\controller\Common; use addons\shopro\controller\Common;
use app\admin\model\shopro\AiTryon as AiTryOnModel; use app\admin\model\shopro\AiTryon as AiTryOnModel;
use app\admin\model\shopro\user\User as UserModel;
use think\Db; use think\Db;
use think\helper\Time;
use addons\shopro\service\goods\GoodsService;
class AiTryon extends Common class AiTryon extends Common
{ {
...@@ -58,4 +62,43 @@ class AiTryon extends Common ...@@ -58,4 +62,43 @@ class AiTryon extends Common
$this->success('我的试戴', $data); $this->success('我的试戴', $data);
} }
/**
* 今日是否可以试戴
*/
public function isTryon()
{
$user = auth_user();
// 查询我的试戴列表
$res = userModel::where('id', $user->id)
->find();
if ($res->ai_count > 4 && $res->ai_time > Time::today()[0]) {
$this->success('不可以试戴', 0);
} else {
if($res->ai_time < Time::today()[0]) {
$ai_count = 1;
} else {
$ai_count = intval($res->ai_count)+1;
}
userModel::where('id', $user->id)->update(['ai_count' => $ai_count, 'ai_time' => time()]);
$this->success('可以试戴', 1);
}
}
/**
* AI试戴 饰品列表
*/
public function jewelryList()
{
auth_user();
// 查询AI试戴饰品列表
// $params = $this->request->param();
$service = new GoodsService();
$service->category(4, true);
$goods = $service->jewelryPaginate();
$this->success('饰品列表', $goods);
}
} }
...@@ -264,6 +264,28 @@ class GoodsService ...@@ -264,6 +264,28 @@ class GoodsService
return $goods; return $goods;
} }
/**
* 获取AI试戴饰品列表
*
* @param bool $is_cache 是否缓存
* @return \think\Paginator
*/
public function jewelryPaginate($is_cache = false)
{
$this->md5s[] = 'paginate';
// 默认排序
$this->order();
$goods = $this->query->field('id,title,subtitle,image')
->cache($this->getCacheKey($is_cache), (200 + mt_rand(0, 100)))
->paginate(request()->param('list_rows', 10))
->toArray();
return $goods;
}
/** /**
* 获取单个商品 * 获取单个商品
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace addons\shopro\service\order; namespace addons\shopro\service\order;
use addons\shopro\service\user\User;
use think\Db; use think\Db;
use addons\shopro\service\goods\GoodsService; use addons\shopro\service\goods\GoodsService;
use addons\shopro\service\pay\PayOper; use addons\shopro\service\pay\PayOper;
...@@ -17,6 +18,7 @@ use app\admin\model\shopro\user\Coupon; ...@@ -17,6 +18,7 @@ use app\admin\model\shopro\user\Coupon;
use app\admin\model\shopro\user\Address as UserAddress; use app\admin\model\shopro\user\Address as UserAddress;
use app\admin\model\shopro\user\Invoice as UserInvoice; use app\admin\model\shopro\user\Invoice as UserInvoice;
use addons\shopro\service\StockSale; use addons\shopro\service\StockSale;
use app\admin\model\shopro\user\User as UserModel;
class OrderCreate class OrderCreate
{ {
...@@ -64,6 +66,16 @@ class OrderCreate ...@@ -64,6 +66,16 @@ class OrderCreate
protected $coupon_id = 0; protected $coupon_id = 0;
/** /**
* 用户积分总数
*/
protected $score = 0;
/**
* 积分可以抵扣的金额(元)
*/
protected $score_deduct_amount = 0;
/**
* 用户备注 * 用户备注
*/ */
protected $remark = 0; protected $remark = 0;
...@@ -99,20 +111,21 @@ class OrderCreate ...@@ -99,20 +111,21 @@ class OrderCreate
*/ */
protected $orderData = [ protected $orderData = [
'goods_original_amount' => '0', // 商品原始总价 'goods_original_amount' => '0', // 商品原始总价
'goods_old_amount' => '0', // 商品不参与活动时的总价 'goods_old_amount' => '0', // 商品不参与活动时的总价
'goods_amount' => '0', // 商品总价 'goods_amount' => '0', // 商品总价
'coupon_discount_fee' => '0', // 优惠券优惠金额 'coupon_discount_fee' => '0', // 优惠券优惠金额
'promo_discount_fee' => 0, // 当前促销优惠总金额 (包含满包邮的邮费) 'promo_discount_fee' => 0, // 当前促销优惠总金额 (包含满包邮的邮费)
'total_discount_fee' => 0, // 当前订单,总优惠金额(优惠券 + 活动优惠) 'total_discount_fee' => 0, // 当前订单,总优惠金额(优惠券 + 活动优惠)
'coupon' => null, // 所使用的优惠券 'coupon' => null, // 所使用的优惠券
'coupon_goods_ids' => [], 'coupon_goods_ids' => [],
'dispatch_amount' => '0', // 运费总价 'dispatch_amount' => '0', // 运费总价
'real_dispatch_amount' => '0', // 免邮减免之后的运费总价,不做计算使用 'real_dispatch_amount' => '0', // 免邮减免之后的运费总价,不做计算使用
'score_amount' => 0, // 订单总积分 'score_amount' => 0, // 订单总积分
'free_shipping_goods_ids' => [], // 满额包邮商品 ids 'free_shipping_goods_ids' => [], // 满额包邮商品 ids
'dispatch_infos' => [], // 当前订单商品按照配送方式分组 'dispatch_infos' => [], // 当前订单商品按照配送方式分组
'order_amount' => 0, // 订单总费用 'order_amount' => 0, // 订单总费用
'pay_fee' => 0 // 应支付总金额 (减去优惠之后的) 'pay_fee' => 0, // 应支付总金额 (减去优惠之后的)
'score_generate' => 0, // 订单产生的积分
]; ];
...@@ -153,6 +166,7 @@ class OrderCreate ...@@ -153,6 +166,7 @@ class OrderCreate
$this->coupon_id = $params['coupon_id'] ?? 0; $this->coupon_id = $params['coupon_id'] ?? 0;
$this->remark = $params['remark'] ?? ''; $this->remark = $params['remark'] ?? '';
$this->score = $params['score'] ?? 0;
$this->money = (isset($params['money']) && $params['money'] > 0) ? $params['money'] : 0; $this->money = (isset($params['money']) && $params['money'] > 0) ? $params['money'] : 0;
// 获取商品信息 // 获取商品信息
...@@ -593,6 +607,22 @@ class OrderCreate ...@@ -593,6 +607,22 @@ class OrderCreate
} }
} }
/**
* 计算积分的抵扣
*
* @return void
*/
public function calcScore()
{
// 获取积分余额
$score = UserModel::where('id', $this->user->id)->value('score');
if ($score) {
//计算积分抵扣金额
$this->score_deduct_amount = round($score/100, 2);
}
}
/** /**
* 获取用户的优惠券列表,可用和不可用的做区分 * 获取用户的优惠券列表,可用和不可用的做区分
...@@ -721,7 +751,23 @@ class OrderCreate ...@@ -721,7 +751,23 @@ class OrderCreate
return compact('can_use', 'cannot_use_msg'); return compact('can_use', 'cannot_use_msg');
} }
/**
* 获取用户的可用积分余额
*
* @return array
*/
public function getScores($calc_type = 'coupons')
{
$this->calc_type = $calc_type;
// 检查是否可下单
$this->calcCheck();
// 计算订单各种费用
$this->calcAmount();
// 用户可用积分余额
return UserModel::where('id', $this->user->id)->value('score', 0, true);
}
/** /**
* 获取匹配的配送规则 * 获取匹配的配送规则
...@@ -969,8 +1015,9 @@ class OrderCreate ...@@ -969,8 +1015,9 @@ class OrderCreate
'temp_remain_pay_fee' => $temp_remain_pay_fee >= 0 ? $temp_remain_pay_fee : 0, // 临时剩余应支付金额,订单确认页面显示 'temp_remain_pay_fee' => $temp_remain_pay_fee >= 0 ? $temp_remain_pay_fee : 0, // 临时剩余应支付金额,订单确认页面显示
'total_discount_fee' => $this->orderData['total_discount_fee'], 'total_discount_fee' => $this->orderData['total_discount_fee'],
'coupon_discount_fee' => $this->orderData['coupon_discount_fee'], 'coupon_discount_fee' => $this->orderData['coupon_discount_fee'],
'promo_discount_fee' => $this->orderData['promo_discount_fee'], // 包含包邮的运费优惠 'promo_discount_fee' => $this->orderData['promo_discount_fee'], // 包含包邮的运费优惠
'money' => $this->money, // 余额支付部分 'money' => $this->money, // 余额支付部分
'score' => $this->score_deduct_amount, // 积分抵扣部分
"invoice_amount" => $this->orderData[$this->invoiceConfig['amount_type']] // 可开票金额 "invoice_amount" => $this->orderData[$this->invoiceConfig['amount_type']] // 可开票金额
]; ];
...@@ -985,7 +1032,8 @@ class OrderCreate ...@@ -985,7 +1032,8 @@ class OrderCreate
'activity_type' => $this->activity['activity']['type'] ?? null, 'activity_type' => $this->activity['activity']['type'] ?? null,
'activity_title' => $this->activity['activity']['title'] ?? null, 'activity_title' => $this->activity['activity']['title'] ?? null,
'promo_types' => array_column($this->activity['promo_infos'], 'activity_type'), 'promo_types' => array_column($this->activity['promo_infos'], 'activity_type'),
'score_amount' => $this->orderData['score_amount'], 'score_amount' => $this->orderData['score_amount'], // 消耗积分
'score_deduct_amount' => $this->score_deduct_amount, // 积分抵扣金额
'goods_list' => $this->goodsList, 'goods_list' => $this->goodsList,
'promo_infos' => $this->activity['promo_infos'], 'promo_infos' => $this->activity['promo_infos'],
"invoice_status" => $this->invoiceConfig['status'], // 发票可开状态 "invoice_status" => $this->invoiceConfig['status'], // 发票可开状态
...@@ -994,11 +1042,12 @@ class OrderCreate ...@@ -994,11 +1042,12 @@ class OrderCreate
"offline_status" => $this->offline_status, "offline_status" => $this->offline_status,
]); ]);
// 如果是下单,合并 优惠券, 收货地址 // 如果是下单,合并 优惠券, 收货地址,积分抵扣金额???
if ($this->calc_type == 'create') { if ($this->calc_type == 'create') {
$result = array_merge($result, [ $result = array_merge($result, [
"coupon" => $this->orderData['coupon'], "coupon" => $this->orderData['coupon'],
"user_address" => $this->userAddress "user_address" => $this->userAddress,
"score_amount" => $this->orderData['score_amount']
]); ]);
} else { } else {
$result = array_merge($result, ['msg' => $this->msg]); $result = array_merge($result, ['msg' => $this->msg]);
...@@ -1037,6 +1086,11 @@ class OrderCreate ...@@ -1037,6 +1086,11 @@ class OrderCreate
$this->calcCoupon(); $this->calcCoupon();
} }
// 计算积分费用
if ($this->score) {
$this->calcScore();
}
// 订单应付金额 // 订单应付金额
$this->orderData['order_amount'] = bcadd($this->orderData['goods_amount'], $this->orderData['dispatch_amount'], 2); $this->orderData['order_amount'] = bcadd($this->orderData['goods_amount'], $this->orderData['dispatch_amount'], 2);
$this->orderData['total_discount_fee'] = bcadd($this->orderData['coupon_discount_fee'], $this->orderData['promo_discount_fee'], 2); $this->orderData['total_discount_fee'] = bcadd($this->orderData['coupon_discount_fee'], $this->orderData['promo_discount_fee'], 2);
......
...@@ -7,6 +7,7 @@ use app\admin\controller\shopro\Common; ...@@ -7,6 +7,7 @@ use app\admin\controller\shopro\Common;
use addons\shopro\service\Wallet as WalletService; use addons\shopro\service\Wallet as WalletService;
use app\admin\model\shopro\user\User as UserModel; use app\admin\model\shopro\user\User as UserModel;
use app\admin\model\shopro\user\Coupon as UserCouponModel; use app\admin\model\shopro\user\Coupon as UserCouponModel;
use traits\model\SoftDelete;
class User extends Common class User extends Common
{ {
...@@ -96,7 +97,7 @@ class User extends Common ...@@ -96,7 +97,7 @@ class User extends Common
$result = Db::transaction(function () use ($list) { $result = Db::transaction(function () use ($list) {
$count = 0; $count = 0;
foreach ($list as $item) { foreach ($list as $item) {
// $count += $item->delete(); // 物理删除慎用 // $count += $item->delete(); // 物理删除,UserModel添加了软删除
$count += $item->save(['status' => 'disabled']); // 改成逻辑删除,状态改为"禁用" $count += $item->save(['status' => 'disabled']); // 改成逻辑删除,状态改为"禁用"
} }
......
...@@ -7,12 +7,15 @@ use app\admin\model\shopro\Coupon as CouponModel; ...@@ -7,12 +7,15 @@ use app\admin\model\shopro\Coupon as CouponModel;
use app\admin\model\shopro\ThirdOauth; use app\admin\model\shopro\ThirdOauth;
use addons\shopro\library\notify\traits\Notifiable; use addons\shopro\library\notify\traits\Notifiable;
use fast\Random; use fast\Random;
use traits\model\SoftDelete;
class User extends Common class User extends Common
{ {
use Notifiable; use Notifiable;
protected $name = 'user'; protected $name = 'user';
use SoftDelete;
protected $deleteTime = 'deletetime';
protected $type = [ protected $type = [
'logintime' => 'timestamp', 'logintime' => 'timestamp',
......
...@@ -4,6 +4,7 @@ namespace app\common\model; ...@@ -4,6 +4,7 @@ namespace app\common\model;
use think\Db; use think\Db;
use think\Model; use think\Model;
use traits\model\SoftDelete;
/** /**
* 会员模型 * 会员模型
...@@ -15,6 +16,9 @@ use think\Model; ...@@ -15,6 +16,9 @@ use think\Model;
class User extends Model class User extends Model
{ {
use SoftDelete;
protected $deleteTime = 'deletetime';
// 开启自动写入时间戳字段 // 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int'; protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名 // 定义时间戳字段名
......
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
"ext-json": "*", "ext-json": "*",
"ext-curl": "*", "ext-curl": "*",
"ext-pdo": "*", "ext-pdo": "*",
"ext-bcmath": "*" "ext-bcmath": "*",
"workerman/phpsocket.io": "^2.2"
}, },
"config": { "config": {
"preferred-install": "dist", "preferred-install": "dist",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment