|
@@ -4,6 +4,7 @@ namespace app\common\service;
|
|
|
|
|
|
|
|
use app\common\model\BoxHandleAllModel;
|
|
use app\common\model\BoxHandleAllModel;
|
|
|
use app\common\model\BoxHandleModel;
|
|
use app\common\model\BoxHandleModel;
|
|
|
|
|
+use app\common\model\GreenScoreLogModel;
|
|
|
use app\common\model\MoneyLogModel;
|
|
use app\common\model\MoneyLogModel;
|
|
|
use app\common\model\RecyclecardLogModel;
|
|
use app\common\model\RecyclecardLogModel;
|
|
|
use app\common\model\ShopGoods;
|
|
use app\common\model\ShopGoods;
|
|
@@ -37,7 +38,7 @@ class BoxHandleService
|
|
|
*/
|
|
*/
|
|
|
public static function make()
|
|
public static function make()
|
|
|
{
|
|
{
|
|
|
- if(!self::$instance){
|
|
|
|
|
|
|
+ if (!self::$instance) {
|
|
|
self::$instance = new static();
|
|
self::$instance = new static();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -56,10 +57,10 @@ class BoxHandleService
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function getBoxListByUser($uid, $params=[], $pageSize=10, $field='')
|
|
|
|
|
|
|
+ public function getBoxListByUser($uid, $params = [], $pageSize = 10, $field = '')
|
|
|
{
|
|
{
|
|
|
- $type = isset($params['type'])? $params['type'] : 0;
|
|
|
|
|
- $boxType = isset($params['box_type'])? $params['box_type'] : 0;
|
|
|
|
|
|
|
+ $type = isset($params['type']) ? $params['type'] : 0;
|
|
|
|
|
+ $boxType = isset($params['box_type']) ? $params['box_type'] : 0;
|
|
|
if (!in_array($type, [1, 2])) {
|
|
if (!in_array($type, [1, 2])) {
|
|
|
sr_throw('订单类型参数错误');
|
|
sr_throw('订单类型参数错误');
|
|
|
}
|
|
}
|
|
@@ -68,55 +69,55 @@ class BoxHandleService
|
|
|
sr_throw('盒子类型参数错误');
|
|
sr_throw('盒子类型参数错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $where = ['r.uid'=>$uid,'r.box_type'=>0,'r.status'=>$type,'r.is_delete'=> 2];
|
|
|
|
|
- if($boxType>0){
|
|
|
|
|
|
|
+ $where = ['r.uid' => $uid, 'r.box_type' => 0, 'r.status' => $type, 'r.is_delete' => 2];
|
|
|
|
|
+ if ($boxType > 0) {
|
|
|
$where['r.box_type'] = $boxType;
|
|
$where['r.box_type'] = $boxType;
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
unset($where['r.box_type']);
|
|
unset($where['r.box_type']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// var_dump($where);
|
|
// var_dump($where);
|
|
|
$list = $this->model->alias('r')
|
|
$list = $this->model->alias('r')
|
|
|
- ->where($where)
|
|
|
|
|
- ->where(function($query) use($params){
|
|
|
|
|
- $keyword = isset($params['keywords'])? trim($params['keywords']):'';
|
|
|
|
|
- if($keyword){
|
|
|
|
|
- $query->where('r.h_sn','like',"%{$keyword}%");
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- ->where(function($query){
|
|
|
|
|
- $query->where('r.open_time','<=',date('Y-m-d H:i:s'))->whereOr('r.open_time','null');
|
|
|
|
|
- })
|
|
|
|
|
- ->where(function($query) use($params){
|
|
|
|
|
- $time = isset($params['time'])? $params['time'] : '';
|
|
|
|
|
- $time1 = isset($params['time1'])? $params['time1'] : '';
|
|
|
|
|
- if($time){
|
|
|
|
|
- $query->where('r.create_time','>=', $time);
|
|
|
|
|
- }else if($time1){
|
|
|
|
|
- $query->where('r.create_time','<', $time1);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- ->field('r.*')
|
|
|
|
|
- ->order('r.create_time desc,r.id desc')
|
|
|
|
|
- ->paginate($pageSize)
|
|
|
|
|
- ->each(function($val, $k){
|
|
|
|
|
- $goodsInfo = ShopGoodsService::make()->getCacheInfoById($val['goods_id'], 'goods_name,goods_sn,goods_img,price,spec_name');
|
|
|
|
|
- $val['goods_name'] = $goodsInfo['goods_name'];
|
|
|
|
|
- $val['goods_sn'] = $goodsInfo['goods_sn'];
|
|
|
|
|
- $val['goods_img'] = $goodsInfo['goods_img'];
|
|
|
|
|
- $val['price'] = $goodsInfo['price'];
|
|
|
|
|
- $val['time_text'] = $val['create_time']? date('H:i:s', strtotime($val['create_time'])):'';
|
|
|
|
|
- $val['spec_name'] = $goodsInfo['spec_name'];
|
|
|
|
|
- if ($val['box_type'] == 10) {
|
|
|
|
|
- $val['is_canrecycle'] = 0;
|
|
|
|
|
- } else {
|
|
|
|
|
- $val['is_canrecycle'] = 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
|
|
+ $keyword = isset($params['keywords']) ? trim($params['keywords']) : '';
|
|
|
|
|
+ if ($keyword) {
|
|
|
|
|
+ $query->where('r.h_sn', 'like', "%{$keyword}%");
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ ->where(function ($query) {
|
|
|
|
|
+ $query->where('r.open_time', '<=', date('Y-m-d H:i:s'))->whereOr('r.open_time', 'null');
|
|
|
|
|
+ })
|
|
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
|
|
+ $time = isset($params['time']) ? $params['time'] : '';
|
|
|
|
|
+ $time1 = isset($params['time1']) ? $params['time1'] : '';
|
|
|
|
|
+ if ($time) {
|
|
|
|
|
+ $query->where('r.create_time', '>=', $time);
|
|
|
|
|
+ } else if ($time1) {
|
|
|
|
|
+ $query->where('r.create_time', '<', $time1);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ ->field('r.*')
|
|
|
|
|
+ ->order('r.create_time desc,r.id desc')
|
|
|
|
|
+ ->paginate($pageSize)
|
|
|
|
|
+ ->each(function ($val, $k) {
|
|
|
|
|
+ $goodsInfo = ShopGoodsService::make()->getCacheInfoById($val['goods_id'], 'goods_name,goods_sn,goods_img,price,spec_name');
|
|
|
|
|
+ $val['goods_name'] = $goodsInfo['goods_name'];
|
|
|
|
|
+ $val['goods_sn'] = $goodsInfo['goods_sn'];
|
|
|
|
|
+ $val['goods_img'] = $goodsInfo['goods_img'];
|
|
|
|
|
+ $val['price'] = $goodsInfo['price'];
|
|
|
|
|
+ $val['time_text'] = $val['create_time'] ? date('H:i:s', strtotime($val['create_time'])) : '';
|
|
|
|
|
+ $val['spec_name'] = $goodsInfo['spec_name'];
|
|
|
|
|
+ if ($val['box_type'] == 10) {
|
|
|
|
|
+ $val['is_canrecycle'] = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $val['is_canrecycle'] = 1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $list = $list?$list->toArray():[];
|
|
|
|
|
- return isset($list['data'])? $list['data'] : [];
|
|
|
|
|
|
|
+ $list = $list ? $list->toArray() : [];
|
|
|
|
|
+ return isset($list['data']) ? $list['data'] : [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -131,10 +132,10 @@ class BoxHandleService
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function getHistoryBoxList($uid, $params=[], $pageSize=10, $field='')
|
|
|
|
|
|
|
+ public function getHistoryBoxList($uid, $params = [], $pageSize = 10, $field = '')
|
|
|
{
|
|
{
|
|
|
- $type = isset($params['type'])? $params['type'] : 0;
|
|
|
|
|
- $boxType = isset($params['box_type'])? $params['box_type'] : 0;
|
|
|
|
|
|
|
+ $type = isset($params['type']) ? $params['type'] : 0;
|
|
|
|
|
+ $boxType = isset($params['box_type']) ? $params['box_type'] : 0;
|
|
|
if (!in_array($type, [1, 2])) {
|
|
if (!in_array($type, [1, 2])) {
|
|
|
sr_throw('订单类型参数错误');
|
|
sr_throw('订单类型参数错误');
|
|
|
}
|
|
}
|
|
@@ -143,36 +144,36 @@ class BoxHandleService
|
|
|
sr_throw('盒子类型参数错误');
|
|
sr_throw('盒子类型参数错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $where = ['r.uid'=>$uid,'r.box_type'=>0,'r.status'=>$type,'r.is_delete'=> 2];
|
|
|
|
|
- if($boxType>0){
|
|
|
|
|
|
|
+ $where = ['r.uid' => $uid, 'r.box_type' => 0, 'r.status' => $type, 'r.is_delete' => 2];
|
|
|
|
|
+ if ($boxType > 0) {
|
|
|
$where['r.box_type'] = $boxType;
|
|
$where['r.box_type'] = $boxType;
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
unset($where['r.box_type']);
|
|
unset($where['r.box_type']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
$list = BoxHandleAllModel::alias('r')
|
|
$list = BoxHandleAllModel::alias('r')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
- ->where(function($query) use($params){
|
|
|
|
|
- $keyword = isset($params['keywords'])? trim($params['keywords']):'';
|
|
|
|
|
- if($keyword){
|
|
|
|
|
- $query->where('r.h_sn','like',"%{$keyword}%");
|
|
|
|
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
|
|
+ $keyword = isset($params['keywords']) ? trim($params['keywords']) : '';
|
|
|
|
|
+ if ($keyword) {
|
|
|
|
|
+ $query->where('r.h_sn', 'like', "%{$keyword}%");
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- ->where(function($query){
|
|
|
|
|
- $query->where('r.open_time','<=',date('Y-m-d H:i:s'))->whereOr('r.open_time','null');
|
|
|
|
|
|
|
+ ->where(function ($query) {
|
|
|
|
|
+ $query->where('r.open_time', '<=', date('Y-m-d H:i:s'))->whereOr('r.open_time', 'null');
|
|
|
})
|
|
})
|
|
|
- ->where('r.create_time','<',date('Y-m-d'))
|
|
|
|
|
|
|
+ ->where('r.create_time', '<', date('Y-m-d'))
|
|
|
->field('r.*')
|
|
->field('r.*')
|
|
|
->order('r.create_time desc,r.id desc')
|
|
->order('r.create_time desc,r.id desc')
|
|
|
->paginate($pageSize)
|
|
->paginate($pageSize)
|
|
|
- ->each(function($val, $k){
|
|
|
|
|
|
|
+ ->each(function ($val, $k) {
|
|
|
$goodsInfo = ShopGoodsService::make()->getCacheInfoById($val['goods_id'], 'goods_name,goods_sn,goods_img,price,spec_name');
|
|
$goodsInfo = ShopGoodsService::make()->getCacheInfoById($val['goods_id'], 'goods_name,goods_sn,goods_img,price,spec_name');
|
|
|
$val['goods_name'] = $goodsInfo['goods_name'];
|
|
$val['goods_name'] = $goodsInfo['goods_name'];
|
|
|
$val['goods_sn'] = $goodsInfo['goods_sn'];
|
|
$val['goods_sn'] = $goodsInfo['goods_sn'];
|
|
|
$val['goods_img'] = $goodsInfo['goods_img'];
|
|
$val['goods_img'] = $goodsInfo['goods_img'];
|
|
|
$val['price'] = $goodsInfo['price'];
|
|
$val['price'] = $goodsInfo['price'];
|
|
|
- $val['time_text'] = $val['create_time']? date('H:i:s', strtotime($val['create_time'])):'';
|
|
|
|
|
|
|
+ $val['time_text'] = $val['create_time'] ? date('H:i:s', strtotime($val['create_time'])) : '';
|
|
|
$val['spec_name'] = $goodsInfo['spec_name'];
|
|
$val['spec_name'] = $goodsInfo['spec_name'];
|
|
|
if ($val['box_type'] == 10) {
|
|
if ($val['box_type'] == 10) {
|
|
|
$val['is_canrecycle'] = 0;
|
|
$val['is_canrecycle'] = 0;
|
|
@@ -182,8 +183,8 @@ class BoxHandleService
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $list = $list?$list->toArray():[];
|
|
|
|
|
- return isset($list['data'])? $list['data'] : [];
|
|
|
|
|
|
|
+ $list = $list ? $list->toArray() : [];
|
|
|
|
|
+ return isset($list['data']) ? $list['data'] : [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -193,34 +194,34 @@ class BoxHandleService
|
|
|
* @param int $dateType
|
|
* @param int $dateType
|
|
|
* @return mixed
|
|
* @return mixed
|
|
|
*/
|
|
*/
|
|
|
- public function getBoxCount($uid,$status,$dateType=1)
|
|
|
|
|
|
|
+ public function getBoxCount($uid, $status, $dateType = 1)
|
|
|
{
|
|
{
|
|
|
- $counts = ['10'=>0,'20'=>0,'30'=>0,'40'=>0];
|
|
|
|
|
|
|
+ $counts = ['10' => 0, '20' => 0, '30' => 0, '40' => 0];
|
|
|
$model = new BoxHandleModel();
|
|
$model = new BoxHandleModel();
|
|
|
// $model = $dateType == 1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
// $model = $dateType == 1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
|
- $datas = $model->where(['uid'=>$uid,'status'=>$status,'is_delete'=>2])
|
|
|
|
|
- ->where(function($query){
|
|
|
|
|
- $query->where('open_time','<=',date('Y-m-d H:i:s'))->whereOr('open_time','null');
|
|
|
|
|
|
|
+ $datas = $model->where(['uid' => $uid, 'status' => $status, 'is_delete' => 2])
|
|
|
|
|
+ ->where(function ($query) {
|
|
|
|
|
+ $query->where('open_time', '<=', date('Y-m-d H:i:s'))->whereOr('open_time', 'null');
|
|
|
})
|
|
})
|
|
|
- ->where(function($query) use($dateType){
|
|
|
|
|
- if($dateType == 1){
|
|
|
|
|
- $query->where('create_time','>=',date('Y-m-d'));
|
|
|
|
|
- }else{
|
|
|
|
|
- $query->where('create_time','<',date('Y-m-d'));
|
|
|
|
|
|
|
+ ->where(function ($query) use ($dateType) {
|
|
|
|
|
+ if ($dateType == 1) {
|
|
|
|
|
+ $query->where('create_time', '>=', date('Y-m-d'));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $query->where('create_time', '<', date('Y-m-d'));
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
->field(Db::raw('box_type,status,count(*) as total'))
|
|
->field(Db::raw('box_type,status,count(*) as total'))
|
|
|
->group('box_type')
|
|
->group('box_type')
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
- $datas = $datas? $datas->toArray() : [];
|
|
|
|
|
- $datas = array_column($datas,'total','box_type');
|
|
|
|
|
- if($datas){
|
|
|
|
|
|
|
+ $datas = $datas ? $datas->toArray() : [];
|
|
|
|
|
+ $datas = array_column($datas, 'total', 'box_type');
|
|
|
|
|
+ if ($datas) {
|
|
|
$counts = [
|
|
$counts = [
|
|
|
- '10'=> isset($datas[10])? $datas[10]:0,
|
|
|
|
|
- '20'=> isset($datas[20])? $datas[20]:0,
|
|
|
|
|
- '30'=> isset($datas[30])? $datas[30]:0,
|
|
|
|
|
- '40'=> isset($datas[40])? $datas[40]:0,
|
|
|
|
|
|
|
+ '10' => isset($datas[10]) ? $datas[10] : 0,
|
|
|
|
|
+ '20' => isset($datas[20]) ? $datas[20] : 0,
|
|
|
|
|
+ '30' => isset($datas[30]) ? $datas[30] : 0,
|
|
|
|
|
+ '40' => isset($datas[40]) ? $datas[40] : 0,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
return $counts;
|
|
return $counts;
|
|
@@ -235,101 +236,103 @@ class BoxHandleService
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function boxDelivery($uid, $params){
|
|
|
|
|
|
|
+ public function boxDelivery($uid, $params)
|
|
|
|
|
+ {
|
|
|
$handIds = $params['hand_ids'];
|
|
$handIds = $params['hand_ids'];
|
|
|
$addressId = $params['address_id'];
|
|
$addressId = $params['address_id'];
|
|
|
|
|
+ sr_throw('发货功能暂未开放');
|
|
|
|
|
|
|
|
- $catchType = isset($params['date_type'])? $params['date_type'] : 0;
|
|
|
|
|
|
|
+ $catchType = isset($params['date_type']) ? $params['date_type'] : 0;
|
|
|
$ids = explode(',', $handIds);
|
|
$ids = explode(',', $handIds);
|
|
|
- if(empty($ids)){
|
|
|
|
|
|
|
+ if (empty($ids)) {
|
|
|
sr_throw('请选择发货的商品');
|
|
sr_throw('请选择发货的商品');
|
|
|
}
|
|
}
|
|
|
- if (!in_array($catchType, [1,2])){
|
|
|
|
|
|
|
+ if (!in_array($catchType, [1, 2])) {
|
|
|
sr_throw('处理参数错误');
|
|
sr_throw('处理参数错误');
|
|
|
}
|
|
}
|
|
|
$model = new BoxHandleModel();
|
|
$model = new BoxHandleModel();
|
|
|
// $model = $catchType==1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
// $model = $catchType==1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
|
$boxList = $model->whereIn('id', $ids)
|
|
$boxList = $model->whereIn('id', $ids)
|
|
|
- ->where(['uid'=>$uid,'status'=>1,'is_delete'=>2])
|
|
|
|
|
|
|
+ ->where(['uid' => $uid, 'status' => 1, 'is_delete' => 2])
|
|
|
->field('id,h_sn,status,uid,rid,handle_type,goods_id,box_type,goods_price')
|
|
->field('id,h_sn,status,uid,rid,handle_type,goods_id,box_type,goods_price')
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
- if (count($boxList) != count($ids)){
|
|
|
|
|
|
|
+ if (count($boxList) != count($ids)) {
|
|
|
sr_throw('商品参数错误或已处理,请刷新后重试');
|
|
sr_throw('商品参数错误或已处理,请刷新后重试');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$addressInfo = UserAddressModel::getAddressIdDetails((int)$addressId, $uid);
|
|
$addressInfo = UserAddressModel::getAddressIdDetails((int)$addressId, $uid);
|
|
|
- if (!$addressInfo){
|
|
|
|
|
|
|
+ if (!$addressInfo) {
|
|
|
sr_throw('地址错误');
|
|
sr_throw('地址错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $i=0;
|
|
|
|
|
|
|
+ $i = 0;
|
|
|
$catchIds = [];
|
|
$catchIds = [];
|
|
|
$orders = $orderGoods = $orderShippings = [];
|
|
$orders = $orderGoods = $orderShippings = [];
|
|
|
- $orderId = ShopOrder::max('order_id')+1;
|
|
|
|
|
|
|
+ $orderId = ShopOrder::max('order_id') + 1;
|
|
|
$curTime = sr_getcurtime(time());
|
|
$curTime = sr_getcurtime(time());
|
|
|
$cacheKey = "caches:box:deliveryCatch:user_{$uid}:";
|
|
$cacheKey = "caches:box:deliveryCatch:user_{$uid}:";
|
|
|
- foreach ($boxList as $key=>$val){
|
|
|
|
|
|
|
+ foreach ($boxList as $key => $val) {
|
|
|
$goodsInfo = ShopGoodsService::make()->getCacheInfoById($val['goods_id']);
|
|
$goodsInfo = ShopGoodsService::make()->getCacheInfoById($val['goods_id']);
|
|
|
- if(empty($goodsInfo)){
|
|
|
|
|
|
|
+ if (empty($goodsInfo)) {
|
|
|
sr_throw('商品参数错误');
|
|
sr_throw('商品参数错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 判断该福袋是否已经处理
|
|
// 判断该福袋是否已经处理
|
|
|
- if($model->where(['id'=>$val['id'],'status'=>2])->value('id')){
|
|
|
|
|
|
|
+ if ($model->where(['id' => $val['id'], 'status' => 2])->value('id')) {
|
|
|
sr_throw('商品已处理');
|
|
sr_throw('商品已处理');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 验证是否有处理订单
|
|
// 验证是否有处理订单
|
|
|
- if(ShopOrder::where(['user_id'=> $uid,'order_source'=> '福袋单号:'.$val['h_sn'],'status'=>1])->value('order_id')){
|
|
|
|
|
|
|
+ if (ShopOrder::where(['user_id' => $uid, 'order_source' => '福袋单号:' . $val['h_sn'], 'status' => 1])->value('order_id')) {
|
|
|
sr_throw('存在已发货商品');
|
|
sr_throw('存在已发货商品');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 订单数据
|
|
// 订单数据
|
|
|
- $orderId = $orderId+$i;
|
|
|
|
|
|
|
+ $orderId = $orderId + $i;
|
|
|
$orders[] = [
|
|
$orders[] = [
|
|
|
- 'order_id'=>$orderId,
|
|
|
|
|
- 'order_sn'=>createdFDOrderSn(),
|
|
|
|
|
- 'payment'=>0,
|
|
|
|
|
- 'ship_postfee'=>0,
|
|
|
|
|
- 'user_id'=>$uid,
|
|
|
|
|
- 'status'=>1,
|
|
|
|
|
- 'num'=>1,
|
|
|
|
|
- 'order_type'=>5,
|
|
|
|
|
- 'order_remark'=> '福袋:'.$val['h_sn'],
|
|
|
|
|
- 'order_source'=> '福袋单号:'.$val['h_sn'],
|
|
|
|
|
- 'supplier_name'=>$goodsInfo['supplier_name'],
|
|
|
|
|
- 'total_price'=>0,
|
|
|
|
|
- 'created_time'=>$curTime,
|
|
|
|
|
- 'rebate_score'=>0,
|
|
|
|
|
|
|
+ 'order_id' => $orderId,
|
|
|
|
|
+ 'order_sn' => createdFDOrderSn(),
|
|
|
|
|
+ 'payment' => 0,
|
|
|
|
|
+ 'ship_postfee' => 0,
|
|
|
|
|
+ 'user_id' => $uid,
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'num' => 1,
|
|
|
|
|
+ 'order_type' => 5,
|
|
|
|
|
+ 'order_remark' => '福袋:' . $val['h_sn'],
|
|
|
|
|
+ 'order_source' => '福袋单号:' . $val['h_sn'],
|
|
|
|
|
+ 'supplier_name' => $goodsInfo['supplier_name'],
|
|
|
|
|
+ 'total_price' => 0,
|
|
|
|
|
+ 'created_time' => $curTime,
|
|
|
|
|
+ 'rebate_score' => 0,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$orderGoods[] = [
|
|
$orderGoods[] = [
|
|
|
- 'order_id'=> $orderId,
|
|
|
|
|
- 'goods_id'=> $goodsInfo['goods_id'],
|
|
|
|
|
- 'goods_name'=> $goodsInfo['goods_name'],
|
|
|
|
|
- 'goods_category'=> $goodsInfo['category'],
|
|
|
|
|
- 'goods_img'=> $goodsInfo['goods_img'],
|
|
|
|
|
- 'num'=>1,
|
|
|
|
|
- 'price'=> $goodsInfo['price'],
|
|
|
|
|
- 'total_fee'=> $goodsInfo['price'],
|
|
|
|
|
- 'spec_ids'=>1,
|
|
|
|
|
- 'spec_text'=> $goodsInfo['spec_name'],
|
|
|
|
|
- 'uid'=>$uid,
|
|
|
|
|
- 'rebate_score'=>0,
|
|
|
|
|
- 'total_rebate_score'=>0
|
|
|
|
|
|
|
+ 'order_id' => $orderId,
|
|
|
|
|
+ 'goods_id' => $goodsInfo['goods_id'],
|
|
|
|
|
+ 'goods_name' => $goodsInfo['goods_name'],
|
|
|
|
|
+ 'goods_category' => $goodsInfo['category'],
|
|
|
|
|
+ 'goods_img' => $goodsInfo['goods_img'],
|
|
|
|
|
+ 'num' => 1,
|
|
|
|
|
+ 'price' => $goodsInfo['price'],
|
|
|
|
|
+ 'total_fee' => $goodsInfo['price'],
|
|
|
|
|
+ 'spec_ids' => 1,
|
|
|
|
|
+ 'spec_text' => $goodsInfo['spec_name'],
|
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
|
+ 'rebate_score' => 0,
|
|
|
|
|
+ 'total_rebate_score' => 0
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$orderShippings[] = [
|
|
$orderShippings[] = [
|
|
|
- 'order_id'=> $orderId,
|
|
|
|
|
- 'sp_name'=> $addressInfo['name'],
|
|
|
|
|
- 'sp_mobile'=> $addressInfo['mobile'],
|
|
|
|
|
- 'sp_province'=> $addressInfo['sp_province'],
|
|
|
|
|
- 'sp_city'=> $addressInfo['sp_city'],
|
|
|
|
|
- 'sp_county'=> $addressInfo['sp_county'],
|
|
|
|
|
- 'sp_remark'=> $addressInfo['remark'],
|
|
|
|
|
- 'sp_mergename'=> $addressInfo['mergename'],
|
|
|
|
|
- 'created_time'=>$curTime
|
|
|
|
|
|
|
+ 'order_id' => $orderId,
|
|
|
|
|
+ 'sp_name' => $addressInfo['name'],
|
|
|
|
|
+ 'sp_mobile' => $addressInfo['mobile'],
|
|
|
|
|
+ 'sp_province' => $addressInfo['sp_province'],
|
|
|
|
|
+ 'sp_city' => $addressInfo['sp_city'],
|
|
|
|
|
+ 'sp_county' => $addressInfo['sp_county'],
|
|
|
|
|
+ 'sp_remark' => $addressInfo['remark'],
|
|
|
|
|
+ 'sp_mergename' => $addressInfo['mergename'],
|
|
|
|
|
+ 'created_time' => $curTime
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$catchIds[] = $val['id'];
|
|
$catchIds[] = $val['id'];
|
|
@@ -337,27 +340,27 @@ class BoxHandleService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 验证处理数据
|
|
// 验证处理数据
|
|
|
- if(empty($orders) || empty($catchIds) || empty($orderGoods) || empty($orderShippings)){
|
|
|
|
|
|
|
+ if (empty($orders) || empty($catchIds) || empty($orderGoods) || empty($orderShippings)) {
|
|
|
sr_throw('发货处理失败');
|
|
sr_throw('发货处理失败');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 插入订单
|
|
// 插入订单
|
|
|
- if(!ShopOrder::insertAll($orders)){
|
|
|
|
|
|
|
+ if (!ShopOrder::insertAll($orders)) {
|
|
|
sr_throw('处理发货订单错误');
|
|
sr_throw('处理发货订单错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 发货订单商品
|
|
// 发货订单商品
|
|
|
- if(!ShopOrderGoodsModel::insertAll($orderGoods)){
|
|
|
|
|
|
|
+ if (!ShopOrderGoodsModel::insertAll($orderGoods)) {
|
|
|
sr_throw('处理发货订单商品数据错误');
|
|
sr_throw('处理发货订单商品数据错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 发货订单信息
|
|
// 发货订单信息
|
|
|
- if(!ShopOrderShippingModel::insertAll($orderShippings)){
|
|
|
|
|
|
|
+ if (!ShopOrderShippingModel::insertAll($orderShippings)) {
|
|
|
sr_throw('处理发单数据错误');
|
|
sr_throw('处理发单数据错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 今日数据处理/历史数据处理
|
|
// 今日数据处理/历史数据处理
|
|
|
- if(!$model->whereIn('id', $catchIds)->update(['status'=>2,'handle_type'=>1,'update_time'=> $curTime])){
|
|
|
|
|
|
|
+ if (!$model->whereIn('id', $catchIds)->update(['status' => 2, 'handle_type' => 1, 'update_time' => $curTime])) {
|
|
|
sr_throw('处理福袋数据失败');
|
|
sr_throw('处理福袋数据失败');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -365,7 +368,7 @@ class BoxHandleService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 一件回收
|
|
|
|
|
|
|
+ * 一件回收 (新的处理回收到绿色积分)
|
|
|
* @param $uid
|
|
* @param $uid
|
|
|
* @param $params
|
|
* @param $params
|
|
|
* @return array
|
|
* @return array
|
|
@@ -374,89 +377,221 @@ class BoxHandleService
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function boxGoodsReBuy($uid, $params){
|
|
|
|
|
|
|
+ public function boxGoodsReBuy($uid, $params)
|
|
|
|
|
+ {
|
|
|
$handIds = $params['hand_ids'];
|
|
$handIds = $params['hand_ids'];
|
|
|
|
|
|
|
|
- $isRetrieve = SystemConfigService::make()->getConfigByName('fudai_is_retrieve',1,'fudai');
|
|
|
|
|
- $isRetrieve = $isRetrieve? $isRetrieve : 0;
|
|
|
|
|
- if(!$isRetrieve){
|
|
|
|
|
|
|
+ $isRetrieve = SystemConfigService::make()->getConfigByName('fudai_is_retrieve', 1, 'fudai');
|
|
|
|
|
+ $isRetrieve = $isRetrieve ? $isRetrieve : 0;
|
|
|
|
|
+ if (!$isRetrieve) {
|
|
|
sr_throw('回收功能已暂时关闭');
|
|
sr_throw('回收功能已暂时关闭');
|
|
|
}
|
|
}
|
|
|
- $catchType = isset($params['date_type'])? $params['date_type'] : 0;
|
|
|
|
|
|
|
+ $catchType = isset($params['date_type']) ? $params['date_type'] : 0;
|
|
|
$ids = explode(',', $handIds);
|
|
$ids = explode(',', $handIds);
|
|
|
- if(empty($ids)){
|
|
|
|
|
|
|
+ if (empty($ids)) {
|
|
|
sr_throw('请选择回收的商品');
|
|
sr_throw('请选择回收的商品');
|
|
|
}
|
|
}
|
|
|
- if (!in_array($catchType, [1,2])){
|
|
|
|
|
|
|
+ if (!in_array($catchType, [1, 2])) {
|
|
|
sr_throw('处理参数错误');
|
|
sr_throw('处理参数错误');
|
|
|
}
|
|
}
|
|
|
$num = count($ids);
|
|
$num = count($ids);
|
|
|
$model = new BoxHandleModel();
|
|
$model = new BoxHandleModel();
|
|
|
// $model = $catchType==1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
// $model = $catchType==1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
|
$boxList = $model->whereIn('id', $ids)
|
|
$boxList = $model->whereIn('id', $ids)
|
|
|
- ->where(['uid'=>$uid,'status'=>1,'is_delete'=>2])
|
|
|
|
|
|
|
+ ->where(['uid' => $uid, 'status' => 1, 'is_delete' => 2])
|
|
|
->field('id,h_sn,status,uid,rid,handle_type,goods_id,box_type,goods_price')
|
|
->field('id,h_sn,status,uid,rid,handle_type,goods_id,box_type,goods_price')
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
- if (count($boxList) != count($ids)){
|
|
|
|
|
|
|
+ if (count($boxList) != count($ids)) {
|
|
|
sr_throw('商品参数错误或已处理,请刷新后重试');
|
|
sr_throw('商品参数错误或已处理,请刷新后重试');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ($model->where('box_type', 10)->where('id', 'in', $ids)->value('id')){
|
|
|
|
|
|
|
+ if ($model->where('box_type', 10)->where('id', 'in', $ids)->value('id')) {
|
|
|
sr_throw('普通商品只能发货,不能回收');
|
|
sr_throw('普通商品只能发货,不能回收');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(UserUnmoneyModel::where(['ids'=> $handIds,'status'=>1])->value('id')){
|
|
|
|
|
|
|
+ if (GreenScoreLogModel::where(['ids' => $handIds])->value('id')) {
|
|
|
sr_throw('商品已处理');
|
|
sr_throw('商品已处理');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 待处理的总金额
|
|
// 待处理的总金额
|
|
|
$totalMoney = $model->where('id', 'in', $ids)->sum('goods_price');
|
|
$totalMoney = $model->where('id', 'in', $ids)->sum('goods_price');
|
|
|
- $serviceFee = $num* env('boxsetting.RECYCLE_ONBOX_PRICE');
|
|
|
|
|
|
|
+ $serviceFee = $num * env('boxsetting.RECYCLE_ONBOX_PRICE');
|
|
|
$endMoney = $totalMoney - $serviceFee;
|
|
$endMoney = $totalMoney - $serviceFee;
|
|
|
- if ($endMoney < 0){
|
|
|
|
|
|
|
+ if ($endMoney < 0) {
|
|
|
sr_throw('错误,请联系客服');
|
|
sr_throw('错误,请联系客服');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 申请
|
|
// 申请
|
|
|
- if ($params['action'] == 'apply'){
|
|
|
|
|
|
|
+ if ($params['action'] == 'apply') {
|
|
|
return [
|
|
return [
|
|
|
- 'total_count'=>count($boxList),
|
|
|
|
|
- 'end_money'=>$endMoney,
|
|
|
|
|
- 'total_money'=>$totalMoney
|
|
|
|
|
|
|
+ 'total_count' => count($boxList),
|
|
|
|
|
+ 'end_money' => $endMoney,
|
|
|
|
|
+ 'total_money' => $totalMoney
|
|
|
];
|
|
];
|
|
|
|
|
+ } // 回收
|
|
|
|
|
+ else if ($params['action'] == 'surerecycle') {
|
|
|
|
|
+ $userInfo = UserService::make()->getCacheInfo($uid, 'id,score,money,green_score,recycle_count,profit_money');
|
|
|
|
|
+ $recycleCount = isset($userInfo['recycle_count']) ? $userInfo['recycle_count'] : 0;
|
|
|
|
|
+ $userGreenScore = isset($userInfo['green_score']) ? $userInfo['green_score'] : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 是否需要扣除回收卡
|
|
|
|
|
+ $needRecycle = false;
|
|
|
|
|
+ if ($needRecycle) {
|
|
|
|
|
+ if ($recycleCount < $num) {
|
|
|
|
|
+ sr_throw('回收卡不足' . $num . '个');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 扣除回收卡
|
|
|
|
|
+ if (!UserModel::where('id', $uid)->dec('recycle_count', $num)->update()) {
|
|
|
|
|
+ sr_throw('回收卡扣除失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
|
+ 'type' => 3,
|
|
|
|
|
+ 'score' => $num,
|
|
|
|
|
+ 'create_at' => sr_getcurtime(time()),
|
|
|
|
|
+ 'state' => 2,
|
|
|
|
|
+ 'before_score' => $recycleCount,
|
|
|
|
|
+ 'after_score' => max(0, $recycleCount - $num),
|
|
|
|
|
+ 'from_id' => 0,
|
|
|
|
|
+ 'uid2' => $handIds
|
|
|
|
|
+ ];
|
|
|
|
|
+ if (!RecyclecardLogModel::insertGetId($data)) {
|
|
|
|
|
+ sr_throw('回收卡扣除处理失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 扣除手续费后的钱全进绿色积分账户
|
|
|
|
|
+ if (!UserModel::where('id', $uid)->inc('green_score', $endMoney)->update()) {
|
|
|
|
|
+ sr_throw('回收商品结算错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
|
+ 'type' => 6,
|
|
|
|
|
+ 'score' => $endMoney,
|
|
|
|
|
+ 'create_at' => sr_getcurtime(time()),
|
|
|
|
|
+ 'state' => 1,
|
|
|
|
|
+ 'before_score' => $userGreenScore,
|
|
|
|
|
+ 'after_score' => floatval($userGreenScore + $endMoney),
|
|
|
|
|
+ 'from_id' => 0,
|
|
|
|
|
+ 'uid2' => 0,
|
|
|
|
|
+ 'ids' => $handIds,
|
|
|
|
|
+ 'remark' => "回收{$num}个福袋商品"
|
|
|
|
|
+ ];
|
|
|
|
|
+ if (!GreenScoreLogModel::insertGetId($data)) {
|
|
|
|
|
+ sr_throw('回收商品结算处理失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 改变处理状态
|
|
|
|
|
+ if (!$model->whereIn('id', $ids)->update(['status' => 2, 'handle_type' => 2, 'update_time' => date('Y-m-d H:i:s')])) {
|
|
|
|
|
+ sr_throw('更新回收处理状态失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $logData = ['ids' => $ids, 'totalMoney' => $totalMoney, 'fee' => $serviceFee, 'back' => $endMoney, 'data' => $data, 'date' => date('Y-m-d H:i:s')];
|
|
|
|
|
+ RedisCache::set("caches:box:recycle:user_{$uid}:" . md5(json_encode($ids)), $logData, 7200);
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'ids' => $ids,
|
|
|
|
|
+ 'total_fee' => $endMoney,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 一件回收(原本回收到余额)
|
|
|
|
|
+ * @param $uid
|
|
|
|
|
+ * @param $params
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ * @throws \think\Exception
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function boxGoodsReBuyBack($uid, $params)
|
|
|
|
|
+ {
|
|
|
|
|
+ $handIds = $params['hand_ids'];
|
|
|
|
|
+
|
|
|
|
|
+ $isRetrieve = SystemConfigService::make()->getConfigByName('fudai_is_retrieve', 1, 'fudai');
|
|
|
|
|
+ $isRetrieve = $isRetrieve ? $isRetrieve : 0;
|
|
|
|
|
+ if (!$isRetrieve) {
|
|
|
|
|
+ sr_throw('回收功能已暂时关闭');
|
|
|
|
|
+ }
|
|
|
|
|
+ $catchType = isset($params['date_type']) ? $params['date_type'] : 0;
|
|
|
|
|
+ $ids = explode(',', $handIds);
|
|
|
|
|
+ if (empty($ids)) {
|
|
|
|
|
+ sr_throw('请选择回收的商品');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!in_array($catchType, [1, 2])) {
|
|
|
|
|
+ sr_throw('处理参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $num = count($ids);
|
|
|
|
|
+ $model = new BoxHandleModel();
|
|
|
|
|
+// $model = $catchType==1? new BoxHandleModel() : new BoxHandleAllModel();
|
|
|
|
|
+ $boxList = $model->whereIn('id', $ids)
|
|
|
|
|
+ ->where(['uid' => $uid, 'status' => 1, 'is_delete' => 2])
|
|
|
|
|
+ ->field('id,h_sn,status,uid,rid,handle_type,goods_id,box_type,goods_price')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ if (count($boxList) != count($ids)) {
|
|
|
|
|
+ sr_throw('商品参数错误或已处理,请刷新后重试');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($model->where('box_type', 10)->where('id', 'in', $ids)->value('id')) {
|
|
|
|
|
+ sr_throw('普通商品只能发货,不能回收');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 回收
|
|
|
|
|
- else if ($params['action'] == 'surerecycle'){
|
|
|
|
|
- $userInfo = UserService::make()->getCacheInfo($uid,'id,score,money,recycle_count,profit_money');
|
|
|
|
|
- $recycleCount = isset($userInfo['recycle_count'])? $userInfo['recycle_count'] : 0;
|
|
|
|
|
- $userProfitMoney = isset($userInfo['profit_money'])? $userInfo['profit_money'] : 0;
|
|
|
|
|
- $userMoney = isset($userInfo['money'])? $userInfo['money'] : 0;
|
|
|
|
|
- $userScore = isset($userInfo['score'])? $userInfo['score'] : 0;
|
|
|
|
|
|
|
+ if (UserUnmoneyModel::where(['ids' => $handIds, 'status' => 1])->value('id')) {
|
|
|
|
|
+ sr_throw('商品已处理');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 待处理的总金额
|
|
|
|
|
+ $totalMoney = $model->where('id', 'in', $ids)->sum('goods_price');
|
|
|
|
|
+ $serviceFee = $num * env('boxsetting.RECYCLE_ONBOX_PRICE');
|
|
|
|
|
+ $endMoney = $totalMoney - $serviceFee;
|
|
|
|
|
+ if ($endMoney < 0) {
|
|
|
|
|
+ sr_throw('错误,请联系客服');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 申请
|
|
|
|
|
+ if ($params['action'] == 'apply') {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'total_count' => count($boxList),
|
|
|
|
|
+ 'end_money' => $endMoney,
|
|
|
|
|
+ 'total_money' => $totalMoney
|
|
|
|
|
+ ];
|
|
|
|
|
+ } // 回收
|
|
|
|
|
+ else if ($params['action'] == 'surerecycle') {
|
|
|
|
|
+ $userInfo = UserService::make()->getCacheInfo($uid, 'id,score,money,recycle_count,profit_money');
|
|
|
|
|
+ $recycleCount = isset($userInfo['recycle_count']) ? $userInfo['recycle_count'] : 0;
|
|
|
|
|
+ $userProfitMoney = isset($userInfo['profit_money']) ? $userInfo['profit_money'] : 0;
|
|
|
|
|
+ $userMoney = isset($userInfo['money']) ? $userInfo['money'] : 0;
|
|
|
|
|
+ $userScore = isset($userInfo['score']) ? $userInfo['score'] : 0;
|
|
|
|
|
|
|
|
// 回收卡扣除
|
|
// 回收卡扣除
|
|
|
- if ($recycleCount < $num){
|
|
|
|
|
- sr_throw('回收卡不足'.$num.'个');
|
|
|
|
|
|
|
+ if ($recycleCount < $num) {
|
|
|
|
|
+ sr_throw('回收卡不足' . $num . '个');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 扣除回收卡
|
|
// 扣除回收卡
|
|
|
- if(!UserModel::where('id',$uid)->dec('recycle_count', $num)->update()){
|
|
|
|
|
|
|
+ if (!UserModel::where('id', $uid)->dec('recycle_count', $num)->update()) {
|
|
|
sr_throw('回收卡扣除失败');
|
|
sr_throw('回收卡扣除失败');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
$data = [
|
|
|
- 'uid'=>$uid,
|
|
|
|
|
- 'type'=>3,
|
|
|
|
|
- 'score'=> $num,
|
|
|
|
|
- 'create_at'=>sr_getcurtime(time()),
|
|
|
|
|
- 'state'=> 2,
|
|
|
|
|
- 'before_score'=> $recycleCount,
|
|
|
|
|
- 'after_score'=> max(0,$recycleCount - $num),
|
|
|
|
|
- 'from_id'=> 0,
|
|
|
|
|
- 'uid2'=> $handIds
|
|
|
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
|
+ 'type' => 3,
|
|
|
|
|
+ 'score' => $num,
|
|
|
|
|
+ 'create_at' => sr_getcurtime(time()),
|
|
|
|
|
+ 'state' => 2,
|
|
|
|
|
+ 'before_score' => $recycleCount,
|
|
|
|
|
+ 'after_score' => max(0, $recycleCount - $num),
|
|
|
|
|
+ 'from_id' => 0,
|
|
|
|
|
+ 'uid2' => $handIds
|
|
|
];
|
|
];
|
|
|
- if(!RecyclecardLogModel::insertGetId($data)){
|
|
|
|
|
|
|
+ if (!RecyclecardLogModel::insertGetId($data)) {
|
|
|
sr_throw('回收卡扣除处理失败');
|
|
sr_throw('回收卡扣除处理失败');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -465,48 +600,48 @@ class BoxHandleService
|
|
|
|
|
|
|
|
// 扣除手续费后的钱除去原价为利润
|
|
// 扣除手续费后的钱除去原价为利润
|
|
|
$profitMoney = max(0, $endMoney - $totalFee);
|
|
$profitMoney = max(0, $endMoney - $totalFee);
|
|
|
- if(!UserModel::where('id', $uid)->inc('money', $totalFee)->update()){
|
|
|
|
|
|
|
+ if (!UserModel::where('id', $uid)->inc('money', $totalFee)->update()) {
|
|
|
sr_throw('回收余额结算错误');
|
|
sr_throw('回收余额结算错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
$data = [
|
|
|
- 'uid'=>$uid,
|
|
|
|
|
- 'type'=> 2,
|
|
|
|
|
- 'money'=> $totalFee,
|
|
|
|
|
- 'create_at'=>sr_getcurtime(time()),
|
|
|
|
|
- 'state'=> 1,
|
|
|
|
|
- 'before_money'=> $userMoney,
|
|
|
|
|
- 'after_money'=> floatval($userMoney + $totalFee),
|
|
|
|
|
- 'from_id'=> 0,
|
|
|
|
|
- 'uid2'=> $handIds,
|
|
|
|
|
- 'free_type'=> 0,
|
|
|
|
|
- 'remark'=> "回收{$num}个福袋商品"
|
|
|
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
|
+ 'type' => 2,
|
|
|
|
|
+ 'money' => $totalFee,
|
|
|
|
|
+ 'create_at' => sr_getcurtime(time()),
|
|
|
|
|
+ 'state' => 1,
|
|
|
|
|
+ 'before_money' => $userMoney,
|
|
|
|
|
+ 'after_money' => floatval($userMoney + $totalFee),
|
|
|
|
|
+ 'from_id' => 0,
|
|
|
|
|
+ 'uid2' => $handIds,
|
|
|
|
|
+ 'free_type' => 0,
|
|
|
|
|
+ 'remark' => "回收{$num}个福袋商品"
|
|
|
];
|
|
];
|
|
|
- if(!MoneyLogModel::insertGetId($data)){
|
|
|
|
|
|
|
+ if (!MoneyLogModel::insertGetId($data)) {
|
|
|
sr_throw('回收商品金额处理失败');
|
|
sr_throw('回收商品金额处理失败');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 利润
|
|
// 利润
|
|
|
- if ($profitMoney>0){
|
|
|
|
|
|
|
+ if ($profitMoney > 0) {
|
|
|
// 利润结算
|
|
// 利润结算
|
|
|
- if(!UserModel::where('id', $uid)->inc('profit_money', $profitMoney)->update()){
|
|
|
|
|
|
|
+ if (!UserModel::where('id', $uid)->inc('profit_money', $profitMoney)->update()) {
|
|
|
sr_throw('回收商品利润结算错误');
|
|
sr_throw('回收商品利润结算错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 添加用户利润记录
|
|
// 添加用户利润记录
|
|
|
$data = [
|
|
$data = [
|
|
|
- 'uid'=>$uid,
|
|
|
|
|
- 'money'=> $profitMoney,
|
|
|
|
|
- 'status'=> 2,
|
|
|
|
|
- 'type'=> 1,
|
|
|
|
|
- 'ids'=> $handIds,
|
|
|
|
|
- 'state'=> 1,
|
|
|
|
|
- 'before_money'=> $userProfitMoney,
|
|
|
|
|
- 'after_money'=> floatval($userProfitMoney + $profitMoney),
|
|
|
|
|
- 'remark'=> "回收{$num}个福袋结算,总金额:{$totalMoney}",
|
|
|
|
|
- 'create_time'=>sr_getcurtime(time())
|
|
|
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
|
+ 'money' => $profitMoney,
|
|
|
|
|
+ 'status' => 2,
|
|
|
|
|
+ 'type' => 1,
|
|
|
|
|
+ 'ids' => $handIds,
|
|
|
|
|
+ 'state' => 1,
|
|
|
|
|
+ 'before_money' => $userProfitMoney,
|
|
|
|
|
+ 'after_money' => floatval($userProfitMoney + $profitMoney),
|
|
|
|
|
+ 'remark' => "回收{$num}个福袋结算,总金额:{$totalMoney}",
|
|
|
|
|
+ 'create_time' => sr_getcurtime(time())
|
|
|
];
|
|
];
|
|
|
- if(!UserUnmoneyModel::insertGetId($data)){
|
|
|
|
|
|
|
+ if (!UserUnmoneyModel::insertGetId($data)) {
|
|
|
sr_throw('商品回收利润处理错误');
|
|
sr_throw('商品回收利润处理错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -515,17 +650,17 @@ class BoxHandleService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 改变用户处理状态
|
|
// 改变用户处理状态
|
|
|
- if(!$model->whereIn('id', $ids)->update(['status'=>2, 'handle_type'=>2, 'update_time'=>date('Y-m-d H:i:s')])){
|
|
|
|
|
- sr_throw('更新回收处理状态失败');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $logData = ['ids'=> $ids,'totalMoney'=> $totalMoney,'fee'=>$serviceFee,'profit'=>$profitMoney,'back'=>$totalFee,'data'=>$data,'date'=>date('Y-m-d H:i:s')];
|
|
|
|
|
- RedisCache::set("caches:box:recycle:user_{$uid}:".md5(json_encode($ids)), $logData, 7200);
|
|
|
|
|
- return [
|
|
|
|
|
- 'ids'=> $ids,
|
|
|
|
|
- 'total_fee'=> $totalFee,
|
|
|
|
|
- 'profit_money'=> $profitMoney
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ if (!$model->whereIn('id', $ids)->update(['status' => 2, 'handle_type' => 2, 'update_time' => date('Y-m-d H:i:s')])) {
|
|
|
|
|
+ sr_throw('更新回收处理状态失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $logData = ['ids' => $ids, 'totalMoney' => $totalMoney, 'fee' => $serviceFee, 'profit' => $profitMoney, 'back' => $totalFee, 'data' => $data, 'date' => date('Y-m-d H:i:s')];
|
|
|
|
|
+ RedisCache::set("caches:box:recycle:user_{$uid}:" . md5(json_encode($ids)), $logData, 7200);
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'ids' => $ids,
|
|
|
|
|
+ 'total_fee' => $totalFee,
|
|
|
|
|
+ 'profit_money' => $profitMoney
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|