105 lines
3.4 KiB
PHP
105 lines
3.4 KiB
PHP
<?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\model\wdsxh\points;
|
||
|
||
use app\admin\model\wdsxh\points\Express;
|
||
use app\admin\model\wdsxh\points\Logistics;
|
||
use app\common\model\wdsxh\points\UserWechatPointsLog;
|
||
use think\Db;
|
||
use think\Exception;
|
||
use think\exception\PDOException;
|
||
use think\exception\ValidateException;
|
||
use think\Model;
|
||
|
||
class Order extends Model
|
||
{
|
||
// 表名
|
||
protected $name = 'wdsxh_points_order';
|
||
|
||
// 自动写入时间戳字段
|
||
protected $autoWriteTimestamp = 'integer';
|
||
|
||
// 定义时间戳字段名
|
||
protected $createTime = 'createtime';
|
||
protected $updateTime = false;
|
||
protected $deleteTime = false;
|
||
|
||
protected $append = [
|
||
'goods_info',
|
||
];
|
||
|
||
protected $type = [
|
||
'redemption_time' => 'timestamp:Y-m-d H:i:s',
|
||
];
|
||
|
||
protected static function init()
|
||
{
|
||
self::beforeInsert(function ($data) {
|
||
$data['order_no'] = wdsxh_create_order();
|
||
|
||
$address = (new \app\api\model\wdsxh\goods\Address())->where('id',$data['address_id'])->find();
|
||
$data['real_name'] = $address['name'];//用户名称
|
||
$data['user_phone'] = $address['tel'];//手机号
|
||
$data['user_address'] = $address['address'];//详细地址
|
||
|
||
$data['redemption_time'] = time();//兑换时间
|
||
|
||
});
|
||
|
||
self::afterInsert(function ($data) {
|
||
$goodsObj = (new Goods())->where('id',$data['goods_id'])->find();
|
||
UserWechatPointsLog::pointsMall(2,$data,$goodsObj,'积分兑换');
|
||
});
|
||
}
|
||
|
||
public function submitSettlement($data)
|
||
{
|
||
$orderModel = new self();
|
||
Db::startTrans();
|
||
try {
|
||
$orderModel->allowField(true)->save($data);
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
throw new \think\Exception($e->getMessage());
|
||
}
|
||
|
||
return ['order_id'=>$orderModel->id];
|
||
|
||
}
|
||
|
||
public function getGoodsInfoAttr($value, $data)
|
||
{
|
||
$goods = (new Goods())
|
||
->withTrashed()
|
||
->where('id',$data['goods_id'])
|
||
->field('name,image')
|
||
->find();
|
||
$goods->points = $data['points'];
|
||
return $goods;
|
||
}
|
||
|
||
/**
|
||
* Desc 获取发货信息
|
||
* Create on 2025/11/13 下午3:46
|
||
* Create by wangyafang
|
||
*/
|
||
public function logistics($order_id){
|
||
$logistics = (new Logistics())
|
||
->where('order_id',$order_id)
|
||
->field('delivery_id,delivery_no,send_time')
|
||
->find();
|
||
$logistics['delivery_name'] = (new Express())->where('id',$logistics['delivery_id'])->value('name');
|
||
$logistics->hidden(['delivery_id']);
|
||
return $logistics;
|
||
|
||
}
|
||
} |