init commit
This commit is contained in:
74
application/api/controller/wdsxh/points/Goods.php
Normal file
74
application/api/controller/wdsxh/points/Goods.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\points;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
class Goods extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\api\model\wdsxh\points\Goods();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->get();
|
||||
$page = isset($param['page']) ? $param['page'] : '';
|
||||
$limit = isset($param['limit']) ? $param['limit'] : 10;
|
||||
$where = [];
|
||||
$where['status'] = array('eq','normal');
|
||||
$total = $this->model->where($where)->count();
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->field('id,name,image,points')
|
||||
->page($page,$limit)
|
||||
->order('weigh desc,createtime desc,id desc')
|
||||
->select();
|
||||
$this->success('请求成功',['total' => $total,'data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 详情
|
||||
* Create on 2025/11/13 上午8:55
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function detail(){
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->get();
|
||||
$id = isset($param['id']) ? $param['id'] : '';
|
||||
if(!$id){
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$where = [];
|
||||
$where['status'] = array('eq','normal');
|
||||
$where['id'] = array('eq',$id);
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->field('id,name,image,slider_images,points,content')
|
||||
->find();
|
||||
if(!$data){
|
||||
$this->error('商品不存在或已下架');
|
||||
}
|
||||
$this->success('请求成功',$data);
|
||||
}
|
||||
}
|
||||
64
application/api/controller/wdsxh/points/MyPoints.php
Normal file
64
application/api/controller/wdsxh/points/MyPoints.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\points;
|
||||
|
||||
use app\admin\model\wdsxh\points\PointsConfig;
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class MyPoints extends Api
|
||||
{
|
||||
protected $noNeedLogin = [''];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $wechat_id = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->wechat_id = (new UserWechat())->where('user_id', $this->auth->id)->value('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 我的积分
|
||||
* Create on 2025/11/14
|
||||
* Create by Claude Code
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
|
||||
try {
|
||||
$userWechat = (new UserWechat())->where('id', $this->wechat_id)->find();
|
||||
|
||||
if (!$userWechat) {
|
||||
$this->error('用户信息不存在');
|
||||
}
|
||||
|
||||
// 获取用户积分
|
||||
$points = $userWechat['points'] ?? 0;
|
||||
|
||||
$data = [
|
||||
'my_points' => $points,
|
||||
'points_description' => (new PointsConfig())->where('id', 1)->value('points_description') ?? '',
|
||||
];
|
||||
|
||||
$this->success('请求成功', $data);
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
180
application/api/controller/wdsxh/points/Order.php
Normal file
180
application/api/controller/wdsxh/points/Order.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\points;
|
||||
|
||||
use app\admin\model\wdsxh\points\Logistics;
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Order extends Api
|
||||
{
|
||||
protected $noNeedLogin = [''];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $model = null;
|
||||
protected $wechat_id = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\api\model\wdsxh\points\Order();
|
||||
$this->wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 提交结算
|
||||
* Create on 2025/11/13 上午10:08
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function submitSettlement()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$data = $this->request->post();
|
||||
try {
|
||||
$validate = new \app\api\validate\wdsxh\points\Order();
|
||||
if (!$validate->scene('submitSettlement')->check($data)) {
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$user_points = (new UserWechat())->where('id',$this->wechat_id)->value('points');
|
||||
$data['points'] = (new \app\api\model\wdsxh\points\Goods())->where('id',$data['goods_id'])->value('points');
|
||||
$data['total_points'] = bcmul($data['points'],$data['number']);
|
||||
if ($data['total_points'] > $user_points) {
|
||||
$this->error('积分不足,无法结算');
|
||||
}
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$data['wechat_id'] = $this->wechat_id;
|
||||
try {
|
||||
$result = (new \app\api\model\wdsxh\points\Order())->submitSettlement($data);
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success('兑换成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 兑换订单列表
|
||||
* Create on 2025/11/13 上午11:52
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->get();
|
||||
$page = isset($param['page']) ? $param['page'] : '';
|
||||
$limit = isset($param['limit']) ? $param['limit'] : 10;
|
||||
$where = [];
|
||||
$where['wechat_id'] = array('eq',$this->wechat_id);
|
||||
if (isset($param['state']) && $param['state'] !== '') {
|
||||
$where['state'] = array('eq',$param['state']);
|
||||
}
|
||||
$total = $this->model->where($where)->count();
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->field('id,order_no,number,goods_id,state,points')
|
||||
->page($page,$limit)
|
||||
->order('id desc')
|
||||
->select();
|
||||
foreach ($data as $k=>&$v){
|
||||
$v->hidden(['goods_id','points']);
|
||||
}
|
||||
$this->success('请求成功',['total' => $total,'data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 订单详情
|
||||
* Create on 2025/11/13 下午1:59
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->get('id','');
|
||||
if(!$id) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
try {
|
||||
$where = [];
|
||||
$where['id'] = array('eq',$id);
|
||||
$where['wechat_id'] = array('eq',$this->wechat_id);
|
||||
$fields = 'id,order_no,number,goods_id,state,real_name,user_phone,user_address,redemption_time,total_points,points';
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->field($fields)
|
||||
->find();
|
||||
if(!$data) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
|
||||
if ($data->state == '3' || $data->state == '4') {
|
||||
$logistics = $this->model->logistics($data->id);
|
||||
$data->logistics = $logistics;
|
||||
}
|
||||
$data->hidden(['goods_id','points']);
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 确认收货
|
||||
* Create on 2025/11/13 下午2:18
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function confirmReceipt(){
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->post('id','');
|
||||
if(!$id) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$where = [];
|
||||
$where['id'] = array('eq',$id);
|
||||
$where['wechat_id'] = array('eq',$this->wechat_id);
|
||||
$where['state'] = array('eq','3');//待收货状态
|
||||
$order = $this->model->where($where)->find();
|
||||
if(!$order) {
|
||||
$this->error('订单不存在或状态异常');
|
||||
}
|
||||
$logisticsObj = (new Logistics())->where('order_id',$id)->find();
|
||||
try {
|
||||
$order->state = '4';//已完成
|
||||
$order->complete_time = time();
|
||||
$order->save();
|
||||
$logisticsObj->receive_time = time();
|
||||
$logisticsObj->save();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('确认收货成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\points;
|
||||
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
|
||||
class UserWechatPointsLog extends Api
|
||||
{
|
||||
protected $noNeedLogin = [''];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $model = null;
|
||||
protected $wechat_id = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\common\model\wdsxh\points\UserWechatPointsLog();
|
||||
$this->wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 积分明细
|
||||
* Create on 2025/11/13 下午5:57
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->get();
|
||||
$page = isset($param['page']) ? $param['page'] : '';
|
||||
$limit = isset($param['limit']) ? $param['limit'] : 10;
|
||||
$where = [];
|
||||
$where['wechat_id'] = array('eq',$this->wechat_id);
|
||||
if (isset($param['change']) && $param['change'] !== '') {
|
||||
$where['change'] = array('eq',$param['change']);
|
||||
}
|
||||
$total = $this->model->where($where)->count();
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->field('change,createtime,points,memo')
|
||||
->page($page,$limit)
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
$this->success('请求成功',['total' => $total,'data' => $data]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user