添加:兑换商品及兑换记录查看
This commit is contained in:
parent
60f5d2030a
commit
7c9bb49c05
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
namespace app\common\dao\user;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\user\ExchangePickupRecord;
|
||||
|
||||
class ExchangePickupRecordDao extends BaseDao{
|
||||
|
||||
protected function getModel(): string{
|
||||
return ExchangePickupRecord::class;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\user;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
|
||||
class ExchangePickupRecord extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): string{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
|
||||
public static function tableName(): string{
|
||||
return 'exchange_pickup_record';
|
||||
}
|
||||
|
||||
|
||||
public function point(){
|
||||
return $this->hasOne(ExchangePickupPoint::class,'id','point_id');
|
||||
}
|
||||
|
||||
public function user(){
|
||||
return $this->hasOne(User::class, 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function staff(){
|
||||
return $this->hasOne(User::class, 'uid', 'staff_uid');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,9 +14,6 @@ class ExchangePickupPointRepository extends BaseRepository{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Common: 编辑信息
|
||||
* Author: wu-hui
|
||||
|
|
@ -25,6 +22,7 @@ class ExchangePickupPointRepository extends BaseRepository{
|
|||
*/
|
||||
public function editInfo($params){
|
||||
$info = $this->dao->getSearch([])->where('id',(int)$params['id'])->findOrEmpty();
|
||||
$info->title = $params['title'];
|
||||
$info->address = $params['address'];
|
||||
$info->is_show = $params['is_show'];
|
||||
$info->uid_list = implode(',',$params['uid_list']);
|
||||
|
|
@ -48,8 +46,12 @@ class ExchangePickupPointRepository extends BaseRepository{
|
|||
->when((int)$params['uid'] > 0,function($query) use ($params){
|
||||
$query->where('find_in_set(' . $params['uid'] . ',`uid_list`)');
|
||||
})
|
||||
->when(isset($params['is_show']) && $params['is_show'] !== '',function($query) use ($params){
|
||||
$query->where('is_show',$params['is_show']);
|
||||
})
|
||||
->when(!empty($params['address']),function($query) use ($params){
|
||||
$query->where('address', "like", "%{$params['address']}%");
|
||||
$query->where('address', "like", "%{$params['address']}%")
|
||||
->whereOr('title','like',"%{$params['address']}%");
|
||||
})
|
||||
->order('create_time DESC,id DESC');
|
||||
$count = $query->count();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\repositories\user;
|
||||
|
||||
use app\common\dao\user\ExchangePickupRecordDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
class ExchangePickupRecordRepository extends BaseRepository{
|
||||
|
||||
protected $dao;
|
||||
|
||||
public function __construct(ExchangePickupRecordDao $dao){
|
||||
$this->dao = $dao;
|
||||
}
|
||||
/**
|
||||
* Common: 获取信息列表
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/14 18:21
|
||||
* @param array $params
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList(array $params,int $page,int $limit):array{
|
||||
$query = $this->dao->getSearch([])
|
||||
->with([
|
||||
'point' => function ($query) {
|
||||
$query->field('id,address as point_address,title as point_title')->bind(['point_address','point_title']);
|
||||
},
|
||||
'user' => function ($query) {
|
||||
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
|
||||
},
|
||||
'staff' => function ($query) {
|
||||
$query->field('uid,nickname as staff_nickname,avatar as staff_avatar')->bind(['staff_nickname','staff_avatar']);
|
||||
},
|
||||
])
|
||||
->when((int)$params['uid'] > 0,function($query) use ($params){
|
||||
$query->where('uid',$params['uid']);
|
||||
})
|
||||
->when((int)$params['staff_uid'] > 0,function($query) use ($params){
|
||||
$query->where('staff_uid',$params['staff_uid']);
|
||||
})
|
||||
->when(!empty($params['address']),function($query) use ($params){
|
||||
$query->hasWhere('point', function ($hasQuery) use ($params) {
|
||||
$hasQuery->where('address', "like", "%{$params['address']}%")
|
||||
->whereOr('title','like',"%{$params['address']}%");
|
||||
})->order('ExchangePickupRecord.create_time DESC,ExchangePickupRecord.id DESC');
|
||||
},function($query){
|
||||
$query->order('create_time DESC,id DESC');
|
||||
});
|
||||
$count = $query->count();
|
||||
$list = $query->page($page,$limit)->select();
|
||||
|
||||
return compact('count','list');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace app\controller\admin\user;
|
|||
use app\common\model\user\ExchangePickupPoint;
|
||||
use app\common\repositories\user\ExchangeIntegralRecordRepository;
|
||||
use app\common\repositories\user\ExchangePickupPointRepository;
|
||||
use app\common\repositories\user\ExchangePickupRecordRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRecordRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
|
|
@ -126,7 +127,8 @@ class ExchangeQuota extends BaseController
|
|||
*/
|
||||
public function pickupPointEdit(){
|
||||
// 参数获取
|
||||
$params = $this->request->params(['id','address','is_show','uid_list']);
|
||||
$params = $this->request->params(['id','title','address','is_show','uid_list']);
|
||||
if(empty($params['title'])) return app('json')->fail('请输入提货点名称!');
|
||||
if(empty($params['address'])) return app('json')->fail('请输入提货点地址!');
|
||||
if(!is_array($params['uid_list']) || count($params['uid_list']) <= 0) return app('json')->fail('请至少选择一个负责人!');
|
||||
// 判断:地址是否已经存在
|
||||
|
|
@ -167,11 +169,19 @@ class ExchangeQuota extends BaseController
|
|||
|
||||
return app('json')->success($data);
|
||||
}
|
||||
// 提货记录
|
||||
/**
|
||||
* Common: 提货记录
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/14 18:21
|
||||
* @return mixed
|
||||
*/
|
||||
public function pickupPointRecord(){
|
||||
[$page, $limit] = $this->getPage();
|
||||
$params = $this->request->params(['uid','address', 'staff_uid']);
|
||||
|
||||
$data = app()->make(ExchangePickupRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit);
|
||||
|
||||
debug('开发中...');
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api\user;
|
||||
|
||||
|
||||
use app\common\model\user\ExchangeIntegralRecord;
|
||||
use app\common\model\user\ExchangePickupRecord;
|
||||
use app\common\model\user\ExchangeQuota;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\user\ExchangePickupPointRepository;
|
||||
use app\common\repositories\user\ExchangeQuotaRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class Exchange extends BaseController{
|
||||
protected $user;
|
||||
|
||||
public function __construct(App $app){
|
||||
parent::__construct($app);
|
||||
$this->user = $this->request->userInfo();
|
||||
}
|
||||
/**
|
||||
* Common: 获取用户持有信息
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/14 16:53
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserHold(){
|
||||
$uid = $this->request->uid();
|
||||
// 获取额度
|
||||
$info = app()->make(ExchangeQuotaRepository::class)
|
||||
->getSearch([])
|
||||
->field([
|
||||
'uid',
|
||||
// 可用额度=剩余额度-冻结额度
|
||||
'(surplus_quota - freeze_quota) as available'
|
||||
])
|
||||
->where('uid',$uid)
|
||||
->findOrEmpty();
|
||||
$info->available_integral = $this->user->exchange_integral;
|
||||
$info->diff_rate = 30;// 差价 应补金额,默认为30%
|
||||
|
||||
return app('json')->success($info);
|
||||
}
|
||||
/**
|
||||
* Common: 获取提货点列表
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/14 16:06
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPointList(){
|
||||
$search = $this->request->params(['uid','address']);
|
||||
$search['is_show'] = 1;
|
||||
$data = app()->make(ExchangePickupPointRepository::class)->getList($search, 1, 30);
|
||||
$list = $data['list'];
|
||||
|
||||
|
||||
return app('json')->success($list);
|
||||
}
|
||||
/**
|
||||
* Common: 兑换处理
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/14 18:02
|
||||
* @return mixed
|
||||
*/
|
||||
public function exchangeHandle(){
|
||||
// 参数获取
|
||||
$data = $this->request->params(['total_money','use_integral','diff_money','diff_money_pay','point_id','staff_uid']);
|
||||
if ((float)$data['total_money'] <= 0) return app('json')->fail('价值必须大于0!');
|
||||
if ((float)$data['point_id'] <= 0) return app('json')->fail('请选择提货点!');
|
||||
if ((float)$data['staff_uid'] <= 0) return app('json')->fail('请选择操作员!');
|
||||
// 添加兑换记录
|
||||
try{
|
||||
$uid = $this->request->uid();
|
||||
Db::transaction(function () use ($data, $uid) {
|
||||
// 添加兑换记录
|
||||
ExchangePickupRecord::insert([
|
||||
'uid' => $uid,
|
||||
'point_id' => $data['point_id'],
|
||||
'staff_uid' => $data['staff_uid'],
|
||||
'total_money' => $data['total_money'],
|
||||
'use_integral' => $data['use_integral'],
|
||||
'diff_money' => $data['diff_money'],
|
||||
'diff_money_pay' => $data['diff_money_pay'],
|
||||
]);
|
||||
// 积分&额度变更数量
|
||||
$changeNum = (float)sprintf("%.2f",$data['total_money'] - $data['diff_money_pay']);
|
||||
// 变更额度
|
||||
$userHoldInfo = ExchangeQuota::where('uid',$uid)->findOrEmpty();
|
||||
$changeFront = (float)$userHoldInfo->surplus_quota;
|
||||
$userHoldInfo->use_quota += (float)$changeNum;
|
||||
$userHoldInfo->surplus_quota -= (float)$changeNum;
|
||||
$userHoldInfo->save();
|
||||
ExchangeQuotaRecord::insert([
|
||||
'uid' => $uid,
|
||||
'product_id' => 0,
|
||||
'order_id' => 0,
|
||||
'order_product_id' => 0,
|
||||
'change_type' => 0,
|
||||
'change_quantity' => (float)$changeNum,
|
||||
'change_front' => $changeFront,
|
||||
'change_after' => (float)$userHoldInfo->surplus_quota,
|
||||
'remark' => "兑换消费",
|
||||
'source' => 2,
|
||||
]);
|
||||
// 变更积分
|
||||
$userInfo = User::where('uid',$uid)->findOrEmpty();
|
||||
$integralChangeFront = (float)$userInfo->exchange_integral;
|
||||
$userInfo->exchange_integral -= (float)$changeNum;
|
||||
$userInfo->save();
|
||||
ExchangeIntegralRecord::insert([
|
||||
'uid' => $uid,
|
||||
'product_id' => 0,
|
||||
'order_id' => 0,
|
||||
'order_product_id' => 0,
|
||||
'change_type' => 0,
|
||||
'change_quantity' => (float)$changeNum,
|
||||
'change_front' => $integralChangeFront,
|
||||
'change_after' => (float)$userInfo->exchange_integral,
|
||||
'remark' => "兑换消费",
|
||||
]);
|
||||
});
|
||||
|
||||
return app('json')->success('success');
|
||||
}catch(\Exception $e){
|
||||
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -344,19 +344,13 @@ Route::group('api/', function () {
|
|||
Route::group('onlinePayment', function () {
|
||||
Route::get('searchMerList', 'OnlinePay/searchMer');
|
||||
Route::get('createOrder', 'OnlinePay/createOrder');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})->prefix('api.store.order.');
|
||||
|
||||
|
||||
|
||||
|
||||
// 商品兑换
|
||||
Route::group('exchange', function () {
|
||||
Route::get('pointList', 'Exchange/getPointList');
|
||||
Route::get('userHold', 'Exchange/getUserHold');
|
||||
Route::get('exchangeHandle', 'Exchange/exchangeHandle');
|
||||
})->prefix('api.user.');
|
||||
|
||||
|
||||
})->middleware(UserTokenMiddleware::class, true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue