0
0

更新代码

This commit is contained in:
2020-08-04 10:09:42 +08:00
parent 6118b5b63b
commit c2ac5d964e
478 changed files with 34410 additions and 0 deletions

140
app/Models/Activity.php Normal file
View File

@@ -0,0 +1,140 @@
<?php
namespace App\Models;
use App\Models\Category;
use App\Models\Favorite;
use RuLong\Order\Contracts\Orderable;
use RuLong\Panel\Models\Storage;
class Activity extends Model implements Orderable
{
const LIFE_ID = '13'; // 娱乐Id
const REC_ID = '14'; // 生活Id
static $name = [
'13' => 'recreation',
'14' => 'life',
];
protected $dates = [
'start_time',
'end_time',
];
public function gifts()
{
return $this->hasMany(ActivityGift::class);
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
public function getStatusAttribute()
{
//未开始
if ($this->start_time > now()) {
return 0;
}
//已结束
if ($this->end_time < now()) {
return -1;
}
if ($this->start_time <= now() && $this->end_time >= now()) {
return 1;
}
}
public function getStatusTextAttribute()
{
if ($this->status == 1) {
return "<span style='color:green'>正常</span>";
} elseif ($this->status == -1) {
return "<span style='color:yellow'>已经结束</span>";
} elseif ($this->status === 0) {
return "<span style='color:blue'>还没开始</span>";
}
}
public function category()
{
return $this->belongsTo(Category::class)->withDefault();
}
public function seller()
{
return $this->belongsTo(Seller::class)->withDefault();
}
public function getTypeAttribute()
{
$cids = Category::whereNotIN('id', [1, 2])->pluck('parent_id', 'id');
$id = $this->category_id;
while ($cids[$id] ?? '') {
$id = $cids[$id];
if ($id == self::LIFE_ID || $id == self::REC_ID) {
return self::$name[$id];
}
}
return '1';
}
public function getStartAtAttribute()
{
return $this->start_time;
}
public function getEndAtAttribute()
{
return $this->end_time;
}
public function getTitle()
{
return $this->title . '-' . $this->price;
}
public function getPrice()
{
return $this->price;
}
public function getScore()
{
return 0;
}
public function getStock()
{
return 0;
}
public function getSellerPrice()
{
return $this->price;
}
public function deductStock($stock)
{
}
public function addStock($stock)
{
}
public function getStorage()
{
return $this->storage;
}
public function getFavoriteAttribute()
{
return Favorite::isFavorite($this->id, 'Activity');
}
}

105
app/Models/ActivityGift.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
namespace App\Models;
use Auth;
use Carbon\Carbon;
use RuLong\Order\Models\Order;
class ActivityGift extends Model
{
public function activity()
{
return $this->belongsTo(Activity::class)->withDefault();
}
/**
* 是否可领取0不可领取,1已经领取,2可领取,负数相差人数
* @Date:2019-01-09T11:24:56+0800
* @return [type] [description]
*/
public function getCanGiftAttribute()
{
$user = Auth::user();
if ($user) {
if ($user->account->act_a == 0) {
//未曾满仓
return 0;
}
//今日时间范围
$toDayTime = [
Carbon::today()->startOfDay()->toDateTimeString(),
Carbon::today()->endOfDay()->toDateTimeString(),
];
$childNum = 0;
$todayLogs = $user->account->logs()->where('type', 'act_a')->count() ?: 0;
if ($user->account->act_a == 1 && $todayLogs) {
//当日第一次满仓人员份额减10
$childNum -= 10;
}
//今日已经领取的活动奖品
$orderList = Order::where('user_id', $user->id)
->where('item_type', 'ACTIVITY_GIFT')
->whereBetween('created_at', $toDayTime)
// ->where('state', 'not in', ['CLOSED', 'CANCEL'])
->whereRaw('substring(cast(status as char),1,1) = 1')
->pluck('item_id');
foreach ($orderList as $key => $item_id) {
//循环判断已经领取的奖品,等于当前奖品的返回已经领取
//不是当前商品的记录消耗数量
if ($item_id == $this->id) {
return 1;
} else {
$childNum -= self::where('id', $item_id)->value('consume_mode') ?: 0;
}
}
$toDayChild = $user->identity->childrentime($toDayTime) + $childNum; //今日总推荐数量
$childNum += $toDayChild; //消耗数量与今日数量抵充
if ($childNum >= $this->mode) {
//满足领取人数可领取
return 2;
} else {
return $childNum - $this->mode;
}
} else {
return 0;
}
}
public function goods()
{
return $this->belongsTo(Goods::class, 'goods_id', 'id');
}
public function param()
{
return $this->belongsTo(GoodsParams::class, 'param_id', 'id');
}
public function getcanCreateOrderAttribute()
{
$data = array();
$data['state'] = false;
$data['tag'] = '兑换';
if ($this->activity->status == 1) {
if ($this->can_gift == 0) {
$data['tag'] = '未满仓';
} elseif ($this->can_gift == 1) {
$data['tag'] = '已领取';
} elseif ($this->can_gift == 2) {
$data['state'] = true;
$data['tag'] = '兑换';
} else {
$data['tag'] = '差' . abs($this->can_gift) . '人';
}
} elseif ($this->activity->status == -1) {
$data['tag'] = '已结束';
} elseif ($this->activity->status == 0) {
$data['tag'] = '未开始';
}
return $data;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Models;
use App\User;
use RuLong\Order\Models\Order;
class ActivityLog extends Model
{
protected $dates = [
'used_at',
];
public function activity()
{
return $this->belongsTo(Activity::class)->withDefault();
}
public function user()
{
return $this->belongsTo(User::class)->withDefault();
}
public function order()
{
return $this->belongsTo(Order::class)->withDefault();
}
public function sanuser()
{
return $this->belongsTo(User::class, 'id', 'san_people_id')->withDefault();
}
public function getStatusTextAttribute()
{
if ($this->used_at == '') {
return '<span style="color:blue">未使用</span>';
} elseif ($this->used_at) {
return '<span style="color:green">已使用</span>';
}
return '';
}
}

19
app/Models/Advert.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use RuLong\Panel\Models\Storage;
class Advert extends Model
{
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
public function seller()
{
return $this->belongsTo(Seller::class)->withDefault();
}
}

24
app/Models/Agency.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use App\User;
class Agency extends Model
{
public function user()
{
return $this->belongsTo(User::class)->withDefault();
}
//业务员
public function salesman()
{
return $this->belongsTo(User::class, 'salesman_id', 'id')->withDefault();
}
protected function getStatusTextAttribute()
{
return $this->status == 1 ? "<span style='color:green'>正常</span>" : "<span style='color:red'>关闭</span>";
}
}

23
app/Models/Article.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use App\Contracts\Advertable;
use Illuminate\Database\Eloquent\Model;
use RuLong\Panel\Models\Storage;
class Article extends Model implements Advertable
{
protected $fillable = ['title','description','content','storage_id','type'];
public function link()
{
return route('articles.show', $this);
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
}

12
app/Models/Bank.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Bank extends Model
{
use SoftDeletes;
}

29
app/Models/Cart.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use App\User;
use Auth;
class Cart extends Model
{
public function params()
{
return $this->belongsTo(GoodsParams::class, 'params_id', 'id');
}
public function user()
{
return $this->belongsTo(User::class);
}
public function lesson()
{
return $this->belongsTo(SellerLesson::class);
}
public function scopeMine($query)
{
return $query->where('user_id', Auth::id());
}
}

63
app/Models/Category.php Normal file
View File

@@ -0,0 +1,63 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use RuLong\Panel\Extensions\Tree;
use RuLong\Panel\Models\Storage;
class Category extends Model
{
use SoftDeletes;
public function parent()
{
return $this->belongsTo(Category::class);
}
public function children()
{
return $this->hasMany(Category::class, 'parent_id');
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
public function goods()
{
return $this->hasMany(Goods::class);
}
public static function treeSelect($parent_id = 0)
{
$menus = self::orderBy('sort', 'asc')->get()->toArray();
$menus = Tree::toFormatTree($menus, 'title', 'id', 'parent_id', $parent_id);
return $menus;
}
public static function treeShow($id = 0)
{
$menus = self::when($id, function ($query) use ($id) {
return $query->where('id', '<>', $id);
})->orderBy('sort', 'asc')->get()->toArray();
$menus = Tree::toFormatTree($menus);
$menus = array_merge([0 => ['id' => 0, 'title_show' => '顶级分类']], $menus);
return $menus;
}
//查找顶级分类id
public static function findTop($id, $topPatentid)
{
$category_ids = Category::orderBy('id', 'desc')->pluck('parent_id', 'id');
do {
$id = $category_ids[$id];
} while ($category_ids[$id] != $topPatentid);
return $id;
}
}

87
app/Models/Cdkey.php Normal file
View File

@@ -0,0 +1,87 @@
<?php
namespace App\Models;
use App\User;
class Cdkey extends Model
{
protected $dates = [
'effective_at',
'used_at',
];
public function user()
{
return $this->belongsTo(User::class)->withDefault();
}
public function belong()
{
return $this->belongsTo(User::class, 'belong_uid')->withDefault();
}
public function getStatusTextAttribute()
{
if ($this->used_at == '') {
return '<span style="color:blue">未使用</span>';
} elseif ($this->used_at) {
return '<span style="color:green">已使用</span>';
}
return '';
}
public function getIsPrintTextAttribute()
{
switch ($this->is_print) {
case 0:
return '<span style="color:blue">否</span>';
break;
case 1:
return '<span style="color:green">是</span>';
break;
}
}
public function generateCard($number)
{
}
/**
* 支付完成之后,直接生产虚拟卡
* @Author:<C.Jason>
* @Date:2018-12-23T17:47:51+0800
* @return function [description]
*/
public function callback()
{
$codes = [];
for ($i = 0; $i < 10; $i++) {
$codes[$i]['belong_uid'] = Auth::id();
$codes[$i]['code'] = $this->random();
$codes[$i]['is_print'] = 0;
$codes[$i]['effective_at'] = now();
$codes[$i]['created_at'] = now();
$codes[$i]['updated_at'] = now();
}
Cdkey::insert($codes);
}
/**
* 产生随机字串,可用来自动生成密码 17010
* @Author:<C.Jason>
* @Date:2018-09-14T17:00:34+0800
* @param integer $len [description]
* @return [type] [description]
*/
private function random($len = 10): string
{
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
$chars = str_repeat($chars, 4);
$chars = str_shuffle($chars);
$str = substr($chars, 0, $len);
return $str;
}
}

32
app/Models/Favorite.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Models;
use App\User;
use Auth;
class Favorite extends Model
{
public function user()
{
return $this->belongsTo(user::class)->withDefault();
}
public function item()
{
return $this->morphTo();
}
public function scopeMine($query)
{
return $query->where('user_id', Auth::id());
}
public static function isFavorite($item_id, $type)
{
$user_id = Auth::id();
$item_type = "App\Models\\" . $type;
$num = Self::where('user_id', $user_id)->where('item_id', $item_id)->where('item_type', $item_type)->count() ?? 0;
return $num;
}
}

23
app/Models/Freight.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use RuLong\Area\Models\Area;
/**
* 邮费模型
*/
class Freight extends Model
{
protected $table = 'seller_freights';
public function seller()
{
return $this->belongsTo(Seller::class);
}
public function area()
{
return $this->belongsTo(Area::class);
}
}

164
app/Models/Goods.php Normal file
View File

@@ -0,0 +1,164 @@
<?php
namespace App\Models;
use Admin;
use App\Contracts\Advertable;
use Illuminate\Database\Eloquent\SoftDeletes;
use RuLong\Order\Contracts\Orderable;
use RuLong\Order\Models\OrderDetail;
use RuLong\Panel\Models\Storage;
class Goods extends Model implements Orderable, Advertable
{
use SoftDeletes;
public function link()
{
return route('goods.show', $this);
}
public function scopeMine($query)
{
return $query->where('seller_id', Admin::user()->seller_id);
}
public function seller()
{
return $this->belongsTo(Seller::class)->withDefault();
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
public function banner()
{
return $this->belongsTo(Storage::class, 'banner_id', 'id')->withDefault();
}
public function category()
{
return $this->belongsTo(Category::class)->withDefault();
}
public function params()
{
return $this->hasMany(GoodsParams::class, 'goods_id', 'id');
}
public function getTitle()
{
return $this->title;
}
public function getPrice()
{
return $this->price;
}
public function getScore()
{
return $this->score;
}
public function getStock()
{
return $this->stock;
}
public function getSellerPrice()
{
return $this->cost;
}
public function deductStock($stock)
{
$this->decrement('stock', $stock);
}
public function addStock($stock)
{
$this->increment('stock', $stock);
}
protected function getMinPriceAttribute()
{
return number_format($this->params()->where('status', 1)->min('price'), 2);
}
protected function getMinOriginalAttribute()
{
return number_format($this->params()->where('status', 1)->min('original'), 2);
}
protected function getMinBaoAttribute()
{
return number_format($this->params()->where('status', 1)->min('taobao'), 2);
}
protected function getMaxScoreAttribute()
{
return number_format($this->params()->where('status', 1)->max('score'), 2);
}
public function cashScore()
{
return $this->params()->where('status', 1)->where('stock', '>', 0)->where('status', 1)->where('score', '>', 0)->whereRaw('price > score')->orderBy('score', 'desc')->first();
}
protected function getScoreRangeAttribute()
{
$params = $this->params()->where('status', 1)->orderBy('score', 'desc')->distinct()->pluck('score');
$params_size = count($params);
if ($params_size == 1) {
return number_format($params[0], 2);
} elseif ($params_size > 1) {
if ($params[$params_size - 1] > 0) {
return number_format($params[0], 2) . '~' . number_format($params[$params_size - 1], 2);
} else {
return number_format($params[0], 2);
}
} else {
return 0.00;
}
}
protected function getStatusTextAttribute()
{
return $this->status == 1 ? "<span style='color:green'>正常</span>" : "<span style='color:red'>已下架</span>";
}
/**
* 是否可删除
* @Author:<ZhaoxiaWang>
* @Date:2018-12-10
* @return boolean
*/
public function canDel(): bool
{
$orderDetails = OrderDetail::whereIn('item_id', $this->params()->pluck('id'))->where('item_type', 'App\Models\GoodsParams')->first();
return $this->status == 1 && empty($orderDetails);
}
/**
* 是否可下架
* @Author:<ZhaoxiaWang>
* @Date:2018-12-10
* @return boolean
*/
public function canCancel(): bool
{
return $this->status == 1 ? true : false;
}
public function isScore(): bool
{
$params = $this->params()->where('status', 1)->where('score', '>', '0')->get();
return $params->count() > 0 ? true : false;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models;
class GoodsParamStock extends Model
{
public function goods()
{
return $this->belongsTo(Goods::class,'goods_id','id');
}
public function param()
{
return $this->belongsTo(GoodsParams::class,'goods_param_id','id');
}
protected function getRuleTextAttribute()
{
switch ($this->rule_sign) {
case 'SHELVE_MANAGER':
return '入库:初始化库存';
case 'UNSHELVE_MANAGER':
return '出库:管理员删除商品';
case 'MALL_GOODS':
return '出库:用户购买商品';
case 'PLUS_MANAGER':
return '入库:管理员商品补仓';
case 'MINUS_MANAGER':
return '出库:管理员出库商品';
default:
return '未知情况';
}
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Models;
use app\common\model\Storage;
use RuLong\Order\Contracts\Orderable;
class GoodsParams extends Model implements Orderable
{
public static function boot()
{
parent::boot();
self::created(function ($model) {
$model->paramStocks()->create(
[
'amount' => $model->stock,
'goods_id' => $model->goods_id ?? 0,
'rule_sign' => 'SHELVE_MANAGER',
]
);
});
self::updated(function ($model) {
$before_stock = $model->getOriginal('stock');
$after_stock = $model->stock;
$change_stock = $after_stock - $before_stock;
if ($change_stock != 0) {
$rule = $change_stock > 0 ? 'PLUS_MANAGER' : 'MINUS_MANAGER';
$model->paramStocks()->create(
[
'amount' => $change_stock,
'goods_id' => $model->goods_id ?? 0,
'rule_sign' => $rule,
]
);
}
});
}
public function goods()
{
return $this->belongsTo(Goods::class, 'goods_id', 'id');
}
public function getTitle()
{
return $this->goods->title . '-' . $this->value;
}
public function getPrice()
{
return $this->price;
}
public function getScore()
{
return $this->score;
}
public function getStock()
{
return $this->stock;
}
public function getSellerPrice()
{
return $this->cost;
}
public function deductStock($stock)
{
$this->decrement('stock', $stock);
}
public function addStock($stock)
{
$this->increment('stock', $stock);
}
protected function getStorageAttribute()
{
return $this->goods->storage;
}
public function paramStocks()
{
return $this->hasMany(GoodsParamStock::class, 'goods_param_id', 'id');
}
public function getStorage()
{
return $this->goods->storage;
}
}

37
app/Models/KeysApply.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
namespace App\Models;
class KeysApply extends Model
{
public function getIsPrintTextAttribute()
{
switch ($this->is_print) {
case 0:
return '<span style="color:blue">否</span>';
break;
case 1:
return '<span style="color:green">是</span>';
break;
}
}
protected function getStatusTextAttribute()
{
if ($this->status == 0) {
return '<span style="color: green">申请中</span>';
} elseif ($this->status == 1) {
return '<span style="color: orangered">已生成</span>';
} elseif ($this->status == 2) {
return '<span style="color: orangered">已驳回</span>';
} else {
return $this->status;
}
}
public function user()
{
return $this->belongsTo(\App\User::class);
}
}

39
app/Models/KeysOrder.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
class KeysOrder extends Model
{
//
public static function boot()
{
parent::boot();
self::creating(function ($model) {
$model->state = 'INIT';
$model->trade_no = 'K' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
});
}
protected function getTypeTextAttribute()
{
if ($this->type == 'BALANCE') {
return '<span style="color: orangered">余额支付</span>';
} elseif ($this->type == 'WECHAT') {
return '<span style="color: green">微信支付</span>';
} else {
return $this->type;
}
}
protected function getStateTextAttribute()
{
if ($this->state == 'SUCCESS') {
return '<span style="color: green">支付完成</span>';
} elseif ($this->state == 'INIT') {
return '<span style="color: orangered">待支付</span>';
} else {
return $this->state;
}
}
}

27
app/Models/Lottery.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
class Lottery extends Model
{
protected $dates = [
'start_at',
'end_at',
];
protected function getStatusTextAttribute()
{
return $this->status == 1 ? "开启" : "关闭";
}
public function logs()
{
return $this->hasMany(LotteryLog::class);
}
public function gifts()
{
return $this->hasMany(LotteryGift::class)->orderBy('level', 'asc');
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace App\Models;
class LotteryGift extends Model
{
static $levels = [
'1' => '一等奖',
'2' => '二等奖',
'3' => '三等奖',
'4' => '四等奖',
'5' => '五等奖',
'6' => '六等奖',
'7' => '七等奖',
'8' => '谢谢参与',
];
static $chances = [
'1' => 0,
'2' => 1,
'3' => 2,
'4' => 7,
'5' => 3,
'6' => 5,
'7' => 4,
'8' => 6,
];
static $types = [
'0' => '谢谢参与',
'1' => '正常奖品',
];
static $class = [
'activity' => 'App\Models\Activity',
'coupon' => 'RuLong\Coupon\Models\CouponInfo',
'goods' => 'App\Models\GoodsParams',
];
public function lottery()
{
return $this->belongsTo(Lottery::class)->withDefault();
}
public function item()
{
return $this->morphTo();
}
public function getLevelTextAttribute()
{
return self::$levels[$this->level] ?? '未知';
}
public function getTypeTextAttribute()
{
return self::$types[$this->type] ?? '未知';
}
public function getClassAttribute()
{
foreach (self::$class as $key => $class) {
if ($this->item_type == $class) {
return $key;
}
}
return 'Null';
}
public function getChanceTextAttribute()
{
$all = $this->lottery->gifts()->sum('chance');
return round($this->chance / $all * 100, 2);
}
public function getTitle()
{
if ($this->item) {
return $this->item->getTitle();
} else {
return '谢谢参与';
}
}
}

33
app/Models/LotteryLog.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use App\User;
use RuLong\Order\Models\Order;
class LotteryLog extends Model
{
protected $dates = [
'used_at',
];
public function user()
{
return $this->belongsTo(User::class)->withDefault();
}
public function lottery()
{
return $this->belongsTo(Lottery::class)->withDefault();
}
public function gift()
{
return $this->belongsTo(LotteryGift::class)->withDefault();
}
public function getOrderAttribute()
{
return Order::where('item_id', $this->id)->where('type', 'lottery')->first();
}
}

12
app/Models/Model.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model as EloquentModel;
class Model extends EloquentModel
{
protected $guarded = [];
}

16
app/Models/Param.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use RuLong\Panel\Models\Storage;
class Param extends Model
{
use SoftDeletes;
public function storage()
{
return $this->hasOne(Storage::class, 'id', 'value')->withDefault();
}
}

46
app/Models/Payment.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
namespace App\Models;
use RuLong\Order\Models\Order;
class Payment extends Model
{
public static function boot()
{
parent::boot();
self::creating(function ($model) {
$model->state = 'INIT';
$model->trade_no = 'T' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
});
}
public function order()
{
return $this->belongsTo(Order::class);
}
protected function getTypeTextAttribute()
{
if($this->type == 'BALANCE'){
return '<span style="color: orangered">余额支付</span>';
}elseif($this->type == 'WECHAT'){
return '<span style="color: green">微信支付</span>';
}else{
return $this->type;
}
}
protected function getStateTextAttribute()
{
if($this->state == 'SUCCESS'){
return '<span style="color: green">支付完成</span>';
}elseif($this->state == 'INIT'){
return '<span style="color: orangered">待支付</span>';
}else{
return $this->state;
}
}
}

66
app/Models/ProfitLog.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use RuLong\Identity\Models\IdentityPoint;
class ProfitLog extends Model
{
protected $dates = [
'end_at',
];
public function getStatusTextAttribute()
{
switch ($this->status) {
case 0:
return '尚未执行';
break;
case 1:
return '已经执行';
break;
}
}
public function portion($id, $user_id = 0)
{
return IdentityPoint::where('identity_id', $id)
->when($user_id, function ($q) use ($user_id) {
$q->where('user_id', $user_id);
})
->where('created_at', '<', $this->end_at)->sum('point');
}
public static function getnow()
{
$time = Carbon::today()->toDateTimeString();
$info = self::where('created_at', $time)->first();
if (!$info) {
$info = self::create([
'price' => 0,
'created_at' => $time,
'end_at' => Carbon::today()->addSecond(86399)->toDateTimeString(),
'status' => 0,
]);
}
return $info;
}
public static function addPrfit($price = 0)
{
$time = Carbon::today()->toDateTimeString();
$info = self::where('created_at', $time)->first();
if ($info) {
$info->price += $price;
$info->save();
} else {
self::create([
'price' => $price,
'created_at' => $time,
'end_at' => Carbon::today()->addSecond(86399)->toDateTimeString(),
'status' => 0,
]);
}
}
}

8
app/Models/Report.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App\Models;
class Report extends Model
{
//
}

8
app/Models/ReportLog.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App\Models;
class ReportLog extends Model
{
//
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Models;
class SalesReport extends Model
{
//
public function seller()
{
return $this->belongsTo(Seller::class)->withDefault();
}
}

224
app/Models/Seller.php Normal file
View File

@@ -0,0 +1,224 @@
<?php
namespace App\Models;
use App\Models\Agency;
use App\Models\Category;
use App\Models\SellerLesson;
use App\User;
use Illuminate\Database\Eloquent\SoftDeletes;
use RuLong\Order\Models\Order;
use RuLong\Panel\Models\Admin;
use RuLong\Panel\Models\Storage;
use \RuLong\Area\Models\OpenArea;
/**
* 商户模型
*/
class Seller extends Model
{
use SoftDeletes;
protected $casts = [
'storage_ids' => 'array',
'cert_ids' => 'array',
];
public static function boot()
{
parent::boot();
// self::created(function ($model) {
// $area_ids = Area::where('type', '省级')->pluck('id');
// foreach ($area_ids as $area_id) {
// $model->freights()->create([
// 'area_id' => $area_id,
// ]);
// }
// });
}
public function admins()
{
return $this->hasMany(Admin::class);
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
public function agency()
{
return $this->belongsTo(Agency::class)->withDefault(['name' => '未设置']);
}
//返回多图
public function getStoragesAttribute()
{
$list = Storage::whereIn('id', $this->storage_ids)->get();
return $list;
}
//返回多图 资质
public function getCertsAttribute()
{
$list = Storage::whereIn('id', $this->cert_ids)->get();
return $list;
}
//封面
public function cover()
{
return $this->belongsTo(Storage::class, 'cover_id', 'id')->withDefault();
}
//微信二维码
public function wechat()
{
return $this->belongsTo(Storage::class, 'wechat_id', 'id')->withDefault();
}
public function freights()
{
return $this->hasMany(Freight::class);
}
public function getGoodsFirst()
{
$goods = Goods::where('seller_id', $this->id)
->whereHas('params', function ($query) {return $query->where('stock', '>', 0)->where('status', 1);})
->where('status', 1)
->orderBy('created_at', 'desc')
->first();
if ($goods) {
return $goods->storage->path ?? '';
} else {
return '';
}
}
public function goods()
{
return $this->hasMany(Goods::class);
}
public function orders()
{
return $this->hasMany(Order::class);
}
/**
* 是否可删除
* @Author:<ZhaoxiaWang>
* @Date:2018-11-30
* @return boolean
*/
public function canDel(): bool
{
return $this->status == 1 && count($this->orders) == 0 && count($this->goods) == 0 ? true : false;
}
/**
* 是否可关闭
* @Author:<ZhaoxiaWang>
* @Date:2018-11-30
* @return boolean
*/
public function canCancel(): bool
{
return $this->status == 1 && $this->goods()->where('status', 1)->count() == 0 ? true : false;
}
protected function getStatusTextAttribute()
{
return $this->status == 1 ? "<span style='color:green'>正常</span>" : "<span style='color:red'>锁定</span>";
}
protected function getTypeTextAttribute()
{
switch ($this->type) {
case 'organ':
return '机构';
break;
case 'seller':
return '商家';
break;
default:
return '未知';
break;
}
}
public function user()
{
return $this->belongsTo(User::class);
}
public function reports()
{
return $this->hasMany(WindupReport::class);
}
protected function getAllAddressAttribute()
{
return str_replace(",", "-", $this->Area->info) . '-' . $this->address;
}
public function Area()
{
return $this->belongsTo(OpenArea::class, 'area_sn', 'sn');
}
public function Province()
{
return $this->belongsTo(OpenArea::class, 'province_sn', 'sn');
}
public function category()
{
return $this->belongsTo(Category::class)->withDefault();
}
public function lesson()
{
return $this->hasMany(SellerLesson::class);
}
public function getTitle()
{
return $this->name;
}
public function salesman()
{
return $this->belongsTo(User::class, 'salesman_id', 'id')->withDefault();
}
//获取屏蔽分类id
public function getTopCateIdAttribute()
{
$cateids = $this->lesson()->pluck('category_id')->toArray();
$parenids = [];
if ($cateids) {
foreach ($cateids as $key => $id) {
$parenids[] = Category::findTop($id, 1);
}
} else {
return [];
}
$findcateids = Category::whereIn('parent_id', $parenids)->OrwhereIn('id', $parenids)->pluck('id')->toArray();
return $findcateids;
}
//机构报课数
public function getLessonLogsCountAttribute()
{
$lessons = $this->lesson()->with(['logs'])->get();
return $lessons->sum('logs_count');
}
}

136
app/Models/SellerLesson.php Normal file
View File

@@ -0,0 +1,136 @@
<?php
namespace App\Models;
use App\Models\SellerLessonLog;
use Auth;
use RuLong\Order\Contracts\Orderable;
use RuLong\Panel\Models\Storage;
class SellerLesson extends Model implements Orderable
{
protected $dates = [
'start_at',
'end_at',
];
public function organ()
{
return $this->belongsTo(Seller::class, 'seller_id', 'id')->withDefault();
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
public function category()
{
return $this->belongsTo(Category::class)->withDefault();
}
protected function getStatusTextAttribute()
{
if ($this->status == 1) {
if ($this->start_at->timestamp > time()) {
return "<span style='color:blue'>还没开始</span>";
} elseif ($this->end_at->timestamp < time()) {
return "<span style='color:yellow'>已经结束</span>";
}
return "<span style='color:green'>正常</span>";
} else {
return "<span style='color:red'>关闭</span>";
}
}
public function logs()
{
return $this->HasMany(SellerLessonLog::class, 'lesson_id', 'id');
}
public function getTitle()
{
return $this->title;
}
public function getPrice()
{
return $this->price;
}
public function getScore()
{
return 0;
}
public function getStock()
{
return $this->stock;
}
public function getSellerPrice()
{
return $this->price;
}
public function deductStock($stock)
{
$this->decrement('stock', $stock);
}
public function addStock($stock)
{
$this->increment('stock', $stock);
}
public function getStorage()
{
return $this->storage;
}
/**
* 可报名
* @return boolean
*/
public function canCart(): bool
{
return Cart::where('user_id', Auth::id())->where('lesson_id', $this->id)->count();
}
protected function getCanCartTextAttribute()
{
return $this->canCart();
}
//是否已购买
public function getBuyTextAttribute()
{
return $this->logs()->where('lesson_id', $this->id)->where('status', 1)->where('user_id', Auth::id())->count() ?? 0;
}
//是否已购买
public function getButtonTextAttribute()
{
if ($this->buy_text) {
return "学习中";
} elseif ($this->canCart()) {
return "已报名";
} else {
return "立即报名";
}
}
//是否已购买
public function getButtonValueAttribute()
{
if ($this->buy_text) {
return 1;
} elseif ($this->canCart()) {
return 2;
} else {
return 0;
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use App\User;
use RuLong\Order\Models\Order;
class SellerLessonLog extends Model
{
public function lesson()
{
return $this->belongsTo(SellerLesson::class)->withDefault();
}
public function user()
{
return $this->belongsTo(User::class)->withDefault();
}
public function order()
{
return $this->belongsTo(Order::class)->withDefault();
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use App\Models\Seller;
use RuLong\Panel\Models\Storage;
class SellerTeacher extends Model
{
public function seller()
{
return $this->belongsto(Seller::class);
}
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
}

50
app/Models/Station.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use RuLong\Order\Contracts\Addressbook;
/**
* 配送点模型
*/
class Station extends Model implements Addressbook
{
use SoftDeletes;
protected $table = 'seller_stations';
/**
* 配送网点名称
* @return string
*/
public function getName(){
return $this->name;
}
/**
* 配送网点电话
* @return string
*/
public function getMobile(){
return $this->mobile;
}
/**
* 配送网点地址
* @return string
*/
public function getAddress(){
return $this->address;
}
public function seller()
{
return $this->belongsTo(Seller::class);
}
}

20
app/Models/Team.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use App\User;
class Team extends Model
{
public function user()
{
return $this->belongsTo(User::class)->withDefault();
}
protected function getTypeTextAttribute()
{
return $this->status == 'alliance' ? "联盟" : "代理";
}
}

8
app/Models/Test.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App\Models;
class Test extends Model
{
//
}

8
app/Models/UserBaby.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App\Models;
class UserBaby extends Model
{
//
}

21
app/Models/UserInfo.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use App\User;
class UserInfo extends Model
{
const UPDATED_AT = null;
protected $primaryKey = 'user_id';
protected $dates = [
'subscribe_at',
];
public function user()
{
return $this->belongsTo(User::class);
}
}

19
app/Models/UserLogin.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use App\User;
class UserLogin extends Model
{
const UPDATED_AT = null;
protected $dates = [
'login_at',
];
public function user()
{
return $this->belongsTo(User::class);
}
}

40
app/Models/VipPament.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use App\User;
class VipPament extends Model
{
public static function boot()
{
parent::boot();
self::creating(function ($model) {
if (!$model->state) {
$model->state = 'INIT';
}
$model->trade_no = 'T' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
});
}
public function getPayTypeAttribute()
{
switch ($this->type) {
case 'WECHAT':
return '微信支付';
break;
case 'CDKEY':
return '激活码';
break;
default:
return '无';
break;
}
}
public function user()
{
return $this->belongsTo(User::class);
}
}

75
app/Models/WechatMenu.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace App\Models;
class WechatMenu extends Model
{
public function children()
{
return $this->hasMany(WechatMenu::class, 'parent_id')->orderBy('sort', 'asc');
}
public function parent()
{
return $this->belongsTo(WechatMenu::class)->withDefault();
}
public static function getPublishArray()
{
$buttons = [];
$menus = self::where('parent_id', 0)->orderBy('sort', 'asc')->get();
foreach ($menus as $key => $menu) {
$button['name'] = $menu->name;
if ($menu->children->isEmpty()) {
$button = array_merge($button, $menu->type_value);
} else {
foreach ($menu->children as $k => $child) {
$subButton['name'] = $child->name;
$subButton = array_merge($subButton, $child->type_value);
$button['sub_button'][$k] = $subButton;
$subButton = [];
}
}
$buttons[] = $button;
$button = [];
}
return $buttons;
}
public function getTypeValueAttribute()
{
switch ($this->type) {
case 'click':
return [
'type' => $this->type,
'key' => $this->value,
];
break;
case 'view':
return [
'type' => $this->type,
'url' => $this->value,
];
break;
case 'miniprogram':
return [
'type' => $this->type,
'url' => explode($this->value)[0],
'appid' => explode($this->value)[1],
'pagepath' => explode($this->value)[2],
];
break;
default:
return [
'type' => 'view',
'url' => $this->value,
];
break;
}
}
}

18
app/Models/WechatRule.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use RuLong\Panel\Models\Storage;
class WechatRule extends Model
{
use SoftDeletes;
public function storage()
{
return $this->belongsTo(Storage::class)->withDefault();
}
}

18
app/Models/Windup.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use RuLong\Order\Models\Order;
class Windup extends Model
{
public function orders()
{
return $this->hasMany(Order::class);
}
public function seller()
{
return $this->belongsTo(Seller::class);
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use RuLong\Order\Models\Order;
class WindupReport extends Model
{
public function orders()
{
return $this->hasMany(Order::class);
}
public function seller()
{
return $this->belongsTo(Seller::class);
}
public function autoReport()
{
$today_arr = explode('-', Carbon::today()->toDateString());
if ($today_arr[2] > 15) {
//本月1=15
$start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
$end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), 15, date("Y")));
} else {
$start = date('Y-m-16 00:00:00', strtotime('-1 month'));
$end = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
}
$sellerids = Seller::get();
foreach ($sellerids as $key => $seller) {
$seller_id = $seller->id;
$orderids = Order::where('seller_id', $seller_id)
->whereHas('logs', function ($query) use ($start, $end) {
$query->where('state', 'DELIVERED|SIGNED')->when($start && $end, function ($query) use ($start, $end) {
$query->whereBetween('created_at', [$start, $end]);
});
})
->where('state', '<>',Order::ORDER_CLOSED)
->pluck('id');
$windup = Order::select(DB::raw('count(*) as orders_count, sum(freight) as freight_sum, sum(seller_freight) as seller_freight_sum, sum(amount) as amount_sum, sum(score) as score_sum,sum(seller_amount) as seller_amount_sum'))
->whereIn('id', $orderids)->first();
$report = WindupReport::where(['seller_id' => $seller_id, 'start_time' => $start, 'end_time' => $end])->first();
if ($orderids->count()>0 && empty($report)) {
DB::transaction(function () use ($seller_id, $start, $end, $windup, $orderids) {
$windup_report = WindupReport::create([
'seller_id' => $seller_id,
'start_time' => $start,
'end_time' => $end,
'orders_count' => $windup->orders_count ?? 0,
'freight_sum' => $windup->freight_sum ?? 0,
'amount_sum' => $windup->amount_sum ?? 0,
'score_sum' => $windup->score_sum ?? 0,
'seller_freight_sum' => $windup->seller_freight_sum ?? 0,
'seller_amount_sum' => $windup->seller_amount_sum ?? 0,
'orderids' => $orderids
]);
Order::whereIn('id', $orderids)->update(['windup_report_id' => $windup_report->id]);
});
}
}
}
}

42
app/Models/Withdraw.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use App\User;
class Withdraw extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
protected function getStateTextAttribute()
{
if ($this->state == 0) {
return '待审核';
} else if ($this->state == -1) {
return '提现失败';
} elseif ($this->state == 1) {
return '成功';
} elseif ($this->state == 2) {
return '驳回';
}
}
protected function getTypeTextAttribute()
{
switch ($this->type) {
case 'Alipay':
return '支付宝';
break;
case 'Wechat':
return '微信零钱';
break;
default:
return '未知';
break;
}
}
}