You've already forked guangan
商品Address
This commit is contained in:
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallAddress extends Model
|
||||
{
|
||||
|
||||
}
|
90
plugs/think-plugs-points-mall/src/model/PointsMallGoods.php
Normal file
90
plugs/think-plugs-points-mall/src/model/PointsMallGoods.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallGoods extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 日志名称
|
||||
* @var string
|
||||
*/
|
||||
protected $oplogName = '商品';
|
||||
|
||||
/**
|
||||
* 日志类型
|
||||
* @var string
|
||||
*/
|
||||
protected $oplogType = '分销商城管理';
|
||||
|
||||
/**
|
||||
* 关联产品规格
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return static::mk()
|
||||
->hasMany(PointsMallGoodsItem::class, 'gcode', 'code')
|
||||
->withoutField('id,status,create_time,update_time')
|
||||
->where(['status' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联商品评论数据
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(PluginWemallUserActionComment::class, 'gcode', 'code')->with('bindUser');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联产品列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function lists(): array
|
||||
{
|
||||
$model = static::mk()->with('items')->withoutField('specs');
|
||||
return $model->order('sort desc,id desc')->where(['deleted' => 0])->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理商品分类数据
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public function getCatesAttr($value): array
|
||||
{
|
||||
$ckey = 'PointsMallGoodsCateItem';
|
||||
$cates = sysvar($ckey) ?: sysvar($ckey, PointsMallGoodsCate::items(true));
|
||||
$cateids = is_string($value) ? str2arr($value) : (array)$value;
|
||||
foreach ($cates as $cate) if (in_array($cate['id'], $cateids)) return $cate;
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置轮播图片
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function setSliderAttr($value): string
|
||||
{
|
||||
return is_string($value) ? $value : (is_array($value) ? arr2str($value) : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取轮播图片
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public function getSliderAttr($value): array
|
||||
{
|
||||
return is_string($value) ? str2arr($value, '|') : [];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\extend\DataExtend;
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallGoodsCate extends Model
|
||||
{
|
||||
/**
|
||||
* 获取上级可用选项
|
||||
* @param int $max 最大级别
|
||||
* @param array $data 表单数据
|
||||
* @param array $parent 上级分类
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function pdata(int $max, array &$data, array $parent = []): array
|
||||
{
|
||||
$items = static::mk()->where(['deleted' => 0])->order('sort desc,id asc')->select()->toArray();
|
||||
$cates = DataExtend::arr2table(empty($parent) ? $items : array_merge([$parent], $items));
|
||||
if (isset($data['id'])) foreach ($cates as $cate) if ($cate['id'] === $data['id']) $data = $cate;
|
||||
foreach ($cates as $key => $cate) {
|
||||
$isSelf = isset($data['spt']) && isset($data['spc']) && $data['spt'] <= $cate['spt'] && $data['spc'] > 0;
|
||||
if ($cate['spt'] >= $max || $isSelf) unset($cates[$key]);
|
||||
}
|
||||
return $cates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据树
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function dtree(): array
|
||||
{
|
||||
$query = static::mk()->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc');
|
||||
return DataExtend::arr2tree($query->withoutField('sort,status,deleted,create_time')->select()->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表数据
|
||||
* @param bool $simple 仅子级别
|
||||
* @return array
|
||||
*/
|
||||
public static function items(bool $simple = false): array
|
||||
{
|
||||
$query = static::mk()->where(['status' => 1, 'deleted' => 0])->order('sort desc,id asc');
|
||||
$cates = array_column(DataExtend::arr2table($query->column('id,pid,name', 'id')), null, 'id');
|
||||
foreach ($cates as $cate) isset($cates[$cate['pid']]) && $cates[$cate['id']]['parent'] =& $cates[$cate['pid']];
|
||||
foreach ($cates as $key => $cate) {
|
||||
$id = $cate['id'];
|
||||
$cates[$id]['ids'][] = $cate['id'];
|
||||
$cates[$id]['names'][] = $cate['name'];
|
||||
while (isset($cate['parent']) && ($cate = $cate['parent'])) {
|
||||
$cates[$id]['ids'][] = $cate['id'];
|
||||
$cates[$id]['names'][] = $cate['name'];
|
||||
}
|
||||
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
|
||||
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
|
||||
if (isset($pky) && $simple && in_array($cates[$pky]['name'], $cates[$id]['names'])) {
|
||||
unset($cates[$pky]);
|
||||
}
|
||||
$pky = $key;
|
||||
}
|
||||
foreach ($cates as &$cate) {
|
||||
unset($cate['sps'], $cate['parent']);
|
||||
}
|
||||
return array_values($cates);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallGoodsItem extends Model
|
||||
{
|
||||
/**
|
||||
* 关联商品信息
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function goods()
|
||||
{
|
||||
return $this->hasOne(PointsMallGoods::class, 'code', 'gcode');
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定商品信息
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function bindGoods()
|
||||
{
|
||||
return $this->goods()->bind([
|
||||
'gname' => 'name',
|
||||
'gcover' => 'cover',
|
||||
'gstatus' => 'status',
|
||||
'gdeleted' => 'deleted'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品规格JSON数据
|
||||
* @param string $code
|
||||
* @return string
|
||||
*/
|
||||
public static function itemsJson(string $code): string
|
||||
{
|
||||
return json_encode(self::itemsArray($code), 64 | 256);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品规格数组
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
public static function itemsArray(string $code): array
|
||||
{
|
||||
return self::mk()->where(['gcode' => $code])->column([
|
||||
'gsku' => 'gsku',
|
||||
'ghash' => 'hash',
|
||||
'gspec' => 'spec',
|
||||
'gcode' => 'gcode',
|
||||
'gimage' => 'image',
|
||||
'status' => 'status',
|
||||
'price_cost' => 'cost',
|
||||
'price_market' => 'market',
|
||||
'price_selling' => 'selling',
|
||||
'allow_balance' => 'allow_balance',
|
||||
'allow_integral' => 'allow_integral',
|
||||
'number_virtual' => 'virtual',
|
||||
'number_express' => 'express',
|
||||
'reward_balance' => 'balance',
|
||||
'reward_integral' => 'integral',
|
||||
], 'ghash');
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallGoodsStock extends Model
|
||||
{
|
||||
|
||||
}
|
97
plugs/think-plugs-points-mall/src/model/PointsMallOrder.php
Normal file
97
plugs/think-plugs-points-mall/src/model/PointsMallOrder.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use plugin\account\model\PluginAccountUser;
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallOrder extends Model
|
||||
{
|
||||
/**
|
||||
* 关联推荐用户
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function from()
|
||||
{
|
||||
return $this->hasOne(PluginAccountUser::class, 'id', 'puid1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联商品数据
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(PointsMallOrderItem::class, 'order_no', 'order_no');
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 关联支付数据
|
||||
// * @return \think\model\relation\HasOne
|
||||
// */
|
||||
// public function payment()
|
||||
// {
|
||||
// return $this->hasOne(PluginPaymentRecord::class, 'order_no', 'order_no')->where([
|
||||
// 'payment_status' => 1,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 关联支付记录
|
||||
// * @return \think\model\relation\HasMany
|
||||
// */
|
||||
// public function payments()
|
||||
// {
|
||||
// return $this->hasMany(PluginPaymentRecord::class, 'order_no', 'order_no')->order('id desc')->withoutField('payment_notify');
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 关联收货地址
|
||||
// * @return \think\model\relation\HasOne
|
||||
// */
|
||||
// public function address()
|
||||
// {
|
||||
// return $this->hasOne(PluginWemallOrderSender::class, 'order_no', 'order_no');
|
||||
// }
|
||||
|
||||
/**
|
||||
* 格式化支付通道
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public function getPaymentAllowsAttr($value): array
|
||||
{
|
||||
$payments = is_string($value) ? str2arr($value) : [];
|
||||
return in_array('all', $payments) ? ['all'] : $payments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间格式处理
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function getPaymentTimeAttr($value): string
|
||||
{
|
||||
return $this->getCreateTimeAttr($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间格式处理
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function setPaymentTimeAttr($value): string
|
||||
{
|
||||
return $this->setCreateTimeAttr($value);
|
||||
}
|
||||
|
||||
public function setConfirmTimeAttr($value): string
|
||||
{
|
||||
return $this->setCreateTimeAttr($value);
|
||||
}
|
||||
|
||||
public function getConfirmTimeAttr($value): string
|
||||
{
|
||||
return $this->getCreateTimeAttr($value);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallOrderCart extends Model
|
||||
{
|
||||
/**
|
||||
* 关联产品数据
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function goods()
|
||||
{
|
||||
return $this->hasOne(PointsMallGoods::class, 'code', 'gcode');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联规格数据
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function specs()
|
||||
{
|
||||
return $this->hasOne(PointsMallGoodsItem::class, 'ghash', 'ghash');
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallOrderItem extends Model
|
||||
{
|
||||
/**
|
||||
* 关联订单信息
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
return $this->hasOne(PointsMallOrder::class, 'order_no', 'order_no');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联商品信息
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function goods()
|
||||
{
|
||||
return $this->hasOne(PointsMallGoods::class, 'code', 'gcode');
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallOrderSender extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 关联订单数据
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
return $this->hasOne(PointsMallOrder::class, 'order_no', 'order_no')->with(['items']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置发货时间
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function setExpressTimeAttr($value): string
|
||||
{
|
||||
return $this->setCreateTimeAttr($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取发货时间
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function getExpressTimeAttr($value): string
|
||||
{
|
||||
return $this->getCreateTimeAttr($value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user