提交代码
This commit is contained in:
17
app/Models/Advert.php
Normal file
17
app/Models/Advert.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Advert extends Model
|
||||
{
|
||||
public $channel_type = [
|
||||
'member' => '会员商城',
|
||||
'pick' => '提货商城',
|
||||
'article' => '资讯',
|
||||
];
|
||||
public function getChannelTextAttribute()
|
||||
{
|
||||
return $this->channel_type[$this->channel] ?? '未知';
|
||||
}
|
||||
|
||||
}
|
||||
8
app/Models/Area.php
Normal file
8
app/Models/Area.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Area extends Model
|
||||
{
|
||||
|
||||
}
|
||||
18
app/Models/Article.php
Normal file
18
app/Models/Article.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function getCoverPathAttribute()
|
||||
{
|
||||
return $this->cover ? env('APP_URL') . '/storage/' . $this->cover : '/assets/index/img/newImg_00_active.png';
|
||||
}
|
||||
|
||||
}
|
||||
56
app/Models/Card.php
Normal file
56
app/Models/Card.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Card extends Model
|
||||
{
|
||||
protected $casts = [
|
||||
'source' => 'array',
|
||||
];
|
||||
protected $dates = [
|
||||
'actived_at',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(CardOrder::class);
|
||||
}
|
||||
|
||||
public function activeUser()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'active_id');
|
||||
}
|
||||
|
||||
public function getStatusTextAttribute()
|
||||
{
|
||||
switch ($this->status) {
|
||||
case 0:
|
||||
return '禁用';
|
||||
break;
|
||||
case 1:
|
||||
return '可用';
|
||||
break;
|
||||
case 2:
|
||||
return '待发货';
|
||||
break;
|
||||
case 3:
|
||||
return '已发货';
|
||||
break;
|
||||
case 4:
|
||||
return '已收货';
|
||||
break;
|
||||
case 5:
|
||||
return '已激活';
|
||||
break;
|
||||
default:
|
||||
return '无';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
app/Models/CardActiveLog.php
Normal file
16
app/Models/CardActiveLog.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class CardActiveLog extends Model
|
||||
{
|
||||
public function card()
|
||||
{
|
||||
return $this->belongsTo(Card::class, 'card_id', 'id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
97
app/Models/CardOrder.php
Normal file
97
app/Models/CardOrder.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use RuLong\Order\Utils\Helper;
|
||||
|
||||
class CardOrder extends Model
|
||||
{
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
self::creating(function ($model) {
|
||||
$model->order_id = Helper::orderid(config('rulong_order.order_orderid.length'), config('rulong_order.order_orderid.prefix'));
|
||||
});
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function card()
|
||||
{
|
||||
return $this->hasMany(Card::class);
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->hasOne(CardPayment::class);
|
||||
}
|
||||
/**
|
||||
* 订单物流
|
||||
* @return CardOrderExpress
|
||||
*/
|
||||
public function express()
|
||||
{
|
||||
return $this->hasOne(CardOrderExpress::class);
|
||||
}
|
||||
|
||||
public function getTypeTextAttribute()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case 'L':
|
||||
return '通用卡【L】';
|
||||
break;
|
||||
case 'K':
|
||||
return '专属卡【K】';
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
return '专属卡【F】';
|
||||
break;
|
||||
|
||||
default:
|
||||
return '未知卡';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getStatusTextAttribute()
|
||||
{
|
||||
switch ($this->status) {
|
||||
case 0:
|
||||
return '未支付';
|
||||
break;
|
||||
case 1:
|
||||
return '已支付';
|
||||
break;
|
||||
case 2:
|
||||
return '已发货';
|
||||
break;
|
||||
case 3:
|
||||
return '已收货';
|
||||
break;
|
||||
case 4:
|
||||
return '已完成';
|
||||
break;
|
||||
default:
|
||||
return '状态错误';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function deliver($company, $number)
|
||||
{
|
||||
$this->express->update([
|
||||
'company' => $company,
|
||||
'number' => $number,
|
||||
'deliver_at' => now(),
|
||||
]);
|
||||
|
||||
$this->status = 2;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
}
|
||||
54
app/Models/CardOrderExpress.php
Normal file
54
app/Models/CardOrderExpress.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Config;
|
||||
|
||||
class CardOrderExpress extends Model
|
||||
{
|
||||
protected $dates = [
|
||||
'deliver_at',
|
||||
'receive_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 所属订单
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-19T13:49:06+0800
|
||||
* @return Order
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(CardOrder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置收货地址详细内容
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-22T10:10:02+0800
|
||||
*/
|
||||
public function setInstanceAttribute($address)
|
||||
{
|
||||
$this->attributes['name'] = $address['name'];
|
||||
$this->attributes['mobile'] = $address['mobile'];
|
||||
$this->attributes['address'] = $address['address'];
|
||||
}
|
||||
|
||||
public function getCompanyTextAttribute()
|
||||
{
|
||||
$deliver_list = Config::get('deliver_list');
|
||||
$array = preg_split('/[\r\n]+/', trim($deliver_list, "\r\n"));
|
||||
|
||||
if (strpos($deliver_list, ':')) {
|
||||
$options = [];
|
||||
foreach ($array as $val) {
|
||||
[$k, $v] = explode(':', $val, 2);
|
||||
$options[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$options = $array;
|
||||
}
|
||||
|
||||
return $options[$this->company]??'未知';
|
||||
}
|
||||
}
|
||||
39
app/Models/CardPayment.php
Normal file
39
app/Models/CardPayment.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class CardPayment extends Model
|
||||
{
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($model) {
|
||||
$model->state = 'INIT';
|
||||
$model->trade_no = 'C' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
|
||||
});
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(CardOrder::class, 'card_order_id', 'id');
|
||||
}
|
||||
|
||||
public function getStateTextAttribute()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case 'INIT':
|
||||
return '<span style="color:#2180ea">未支付</span>';
|
||||
break;
|
||||
case 'SUCCESS':
|
||||
return '<span style="color:#14d000">已支付</span>';
|
||||
break;
|
||||
case 'OVER':
|
||||
return '<span style="color:#ff0000">已结束</span>';
|
||||
break;
|
||||
default:
|
||||
return "未知状态";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
app/Models/Cart.php
Normal file
23
app/Models/Cart.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Auth;
|
||||
|
||||
class Cart extends Model
|
||||
{
|
||||
public function goods()
|
||||
{
|
||||
return $this->belongsTo(Goods::class, 'goods_id', 'id');
|
||||
}
|
||||
|
||||
public function params()
|
||||
{
|
||||
return $this->belongsTo(GoodsParams::class, 'params_id', 'id');
|
||||
}
|
||||
|
||||
public function scopeMine($query)
|
||||
{
|
||||
return $query->where('user_id', Auth::id());
|
||||
}
|
||||
}
|
||||
11
app/Models/CashAccount.php
Normal file
11
app/Models/CashAccount.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class CashAccount extends Model
|
||||
{
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
43
app/Models/Cashout.php
Normal file
43
app/Models/Cashout.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Cashout extends Model
|
||||
{
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function cashAccount()
|
||||
{
|
||||
return $this->belongsTo(CashAccount::class);
|
||||
}
|
||||
|
||||
public function getStateTextAttribute()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case 'INIT':
|
||||
return '审核中';
|
||||
break;
|
||||
case 'PASS':
|
||||
return '通过';
|
||||
break;
|
||||
case 'REJECT':
|
||||
return '驳回';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function pass()
|
||||
{
|
||||
$this->state = "PASS";
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function reject()
|
||||
{
|
||||
$this->state = "REJECT";
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
30
app/Models/Category.php
Normal file
30
app/Models/Category.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public function goods()
|
||||
{
|
||||
return $this->belongsToMany(Goods::class, 'goods_category')->withTimestamps();
|
||||
}
|
||||
|
||||
public function getCoverPathAttribute()
|
||||
{
|
||||
if ($this->cover) {
|
||||
return env('APP_URL') . '/storage/' . $this->cover;
|
||||
} else {
|
||||
return '/assets/index/img/product_active.png';
|
||||
}
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id', 'id');
|
||||
}
|
||||
}
|
||||
27
app/Models/Config.php
Normal file
27
app/Models/Config.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Config extends Model
|
||||
{
|
||||
protected $table = 'admin_config';
|
||||
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
|
||||
protected function setValueAttribute($value)
|
||||
{
|
||||
switch (strtolower($value)) {
|
||||
case 'on':
|
||||
$value = 1;
|
||||
break;
|
||||
case 'off':
|
||||
$value = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->attributes['value'] = $value;
|
||||
}
|
||||
}
|
||||
161
app/Models/Goods.php
Normal file
161
app/Models/Goods.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Overtrue\LaravelFollow\Traits\CanBeFavorited;
|
||||
use RuLong\Order\Contracts\Orderable;
|
||||
|
||||
class Goods extends Model implements Orderable
|
||||
{
|
||||
use SoftDeletes, CanBeFavorited;
|
||||
|
||||
public $typeArray = [
|
||||
'member' => '会员商品',
|
||||
'pick' => '提货商品',
|
||||
];
|
||||
|
||||
public function link()
|
||||
{
|
||||
return route('goods.show', $this);
|
||||
}
|
||||
|
||||
protected function getTypeTextAttribute()
|
||||
{
|
||||
return $this->typeArray[$this->type] ?? '未知';
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class)->withDefault();
|
||||
}
|
||||
|
||||
public function params()
|
||||
{
|
||||
return $this->hasMany(GoodsParams::class, 'goods_id', 'id')->where('status', 1);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function addSold($sold)
|
||||
{
|
||||
$this->increment('sold', $sold);
|
||||
}
|
||||
|
||||
protected function getMinPriceAttribute()
|
||||
{
|
||||
return number_format($this->params()->min('price'), 2);
|
||||
}
|
||||
|
||||
protected function getDefMinPriceAttribute()
|
||||
{
|
||||
if (Auth::user() && Auth::user()->identity_id > 0) {
|
||||
return number_format($this->params()->min('price'), 2);
|
||||
} else {
|
||||
return number_format($this->params()->min('original'), 2);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getMinOriginalAttribute()
|
||||
{
|
||||
return number_format($this->params()->min('original'), 2);
|
||||
}
|
||||
|
||||
protected function getAllStockAttribute()
|
||||
{
|
||||
return $this->params()->sum('stock') ?? 0;
|
||||
}
|
||||
|
||||
protected function getScoreRangeAttribute()
|
||||
{
|
||||
$params = $this->params()->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()
|
||||
{
|
||||
switch ($this->status) {
|
||||
case -1:
|
||||
return "<span style='color:blue'>待审核</span>";
|
||||
break;
|
||||
case 0:
|
||||
return "<span style='color:red'>下架</span>";
|
||||
break;
|
||||
case 1:
|
||||
return "<span style='color:green'>正常</span>";
|
||||
break;
|
||||
default:
|
||||
return "<span style='color:yellow'>未知</span>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getIsFavoriteAttribute()
|
||||
{
|
||||
$user = Auth::user();
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isFavoritedBy($user)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getCoverPathAttribute()
|
||||
{
|
||||
if ($this->cover) {
|
||||
return env('APP_URL') . '/storage/' . $this->cover;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
app/Models/GoodsParams.php
Normal file
72
app/Models/GoodsParams.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use RuLong\Order\Contracts\Orderable;
|
||||
|
||||
class GoodsParams extends Model implements Orderable
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
public function goods()
|
||||
{
|
||||
return $this->belongsTo(Goods::class, 'goods_id', 'id');
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->goods ? $this->goods->title . '-' . $this->value : '';
|
||||
}
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
public function getParticipate()
|
||||
{
|
||||
return $this->participate;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function addSold($sold)
|
||||
{
|
||||
$this->goods()->increment('sold', $sold);
|
||||
}
|
||||
|
||||
protected function getStorageAttribute()
|
||||
{
|
||||
return $this->goods ? $this->goods->cover_path : '';
|
||||
}
|
||||
|
||||
public function getFreight($address, $number)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
97
app/Models/Mobile.php
Normal file
97
app/Models/Mobile.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use RuLong\Area\Models\Area;
|
||||
use RuLong\Order\Contracts\Orderable;
|
||||
|
||||
class Mobile extends Model implements Orderable
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->charge;
|
||||
}
|
||||
|
||||
public function getScore()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getStock()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function deductStock($stock)
|
||||
{
|
||||
}
|
||||
|
||||
public function addStock($stock)
|
||||
{
|
||||
}
|
||||
|
||||
public function addSold($number)
|
||||
{
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function getOperatorTextAttribute()
|
||||
{
|
||||
return config('pick.operators')[$this->operator] ?? '未知';
|
||||
}
|
||||
|
||||
public function Province()
|
||||
{
|
||||
return $this->belongsTo(Area::class, 'province_sn', 'sn');
|
||||
}
|
||||
|
||||
public function city()
|
||||
{
|
||||
return $this->belongsTo(Area::class, 'city_sn', 'sn');
|
||||
}
|
||||
|
||||
public function area()
|
||||
{
|
||||
return $this->belongsTo(Area::class, 'area_sn', 'sn');
|
||||
}
|
||||
|
||||
public function getStorageAttribute()
|
||||
{
|
||||
return config('pick.imgs')[$this->operator];
|
||||
}
|
||||
|
||||
public function paid($user_id)
|
||||
{
|
||||
$this->status = 2;
|
||||
$this->user_id = $user_id;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getStatusTextAttribute()
|
||||
{
|
||||
switch ($this->status) {
|
||||
case 1:
|
||||
return '正常';
|
||||
break;
|
||||
case 2:
|
||||
return '已售';
|
||||
break;
|
||||
case 0:
|
||||
return '禁用';
|
||||
break;
|
||||
default:
|
||||
return '未知';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
app/Models/Model.php
Normal file
12
app/Models/Model.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as EloquentModel;
|
||||
|
||||
class Model extends EloquentModel
|
||||
{
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
}
|
||||
64
app/Models/Payment.php
Normal file
64
app/Models/Payment.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use RuLong\Order\Models\Order;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
protected $casts = [
|
||||
'source' => 'array',
|
||||
];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function getTypeTextAttribute()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case 'WECHAT':
|
||||
return "微信支付";
|
||||
break;
|
||||
case 'ALIPAY':
|
||||
return "支付宝支付";
|
||||
break;
|
||||
case 'BALANCE':
|
||||
return "余额支付";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "未知类型";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getStateTextAttribute()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case 'INIT':
|
||||
return '<span style="color:#2180ea">未支付</span>';
|
||||
break;
|
||||
case 'SUCCESS':
|
||||
return '<span style="color:#14d000">已支付</span>';
|
||||
break;
|
||||
case 'OVER':
|
||||
return '<span style="color:#ff0000">已结束</span>';
|
||||
break;
|
||||
default:
|
||||
return "未知状态";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
app/Models/Profit.php
Normal file
22
app/Models/Profit.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use RuLong\Identity\Models\Identity;
|
||||
|
||||
class Profit extends Model
|
||||
{
|
||||
protected $dates = [
|
||||
'setted_at',
|
||||
];
|
||||
|
||||
public function identity()
|
||||
{
|
||||
return $this->belongsTo(Identity::class);
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(ProfitLog::class);
|
||||
}
|
||||
}
|
||||
17
app/Models/ProfitLog.php
Normal file
17
app/Models/ProfitLog.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class ProfitLog extends Model
|
||||
{
|
||||
|
||||
public function profit()
|
||||
{
|
||||
return $this->belongsTo(Profit::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
69
app/Models/UpgradePayment.php
Normal file
69
app/Models/UpgradePayment.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UpgradePayment extends Model
|
||||
{
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($model) {
|
||||
$model->state = $model->state ?? 'INIT';
|
||||
$model->trade_no = 'U' . date('ymdHis') . sprintf("%07d", mt_rand(0, pow(10, 7) - 1));
|
||||
});
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function getTypeTextAttribute()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case 'vip':
|
||||
return "升级会员";
|
||||
break;
|
||||
case 'agent':
|
||||
return "升级代理商";
|
||||
break;
|
||||
default:
|
||||
return "未知类型";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPayTypeTextAttribute()
|
||||
{
|
||||
switch ($this->pay_type) {
|
||||
case 'WECHAT':
|
||||
return "微信支付";
|
||||
break;
|
||||
case 'ADMIN':
|
||||
return "空升";
|
||||
break;
|
||||
default:
|
||||
return "未知类型";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getStateTextAttribute()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case 'INIT':
|
||||
return '<span style="color:#2180ea">未支付</span>';
|
||||
break;
|
||||
case 'SUCCESS':
|
||||
return '<span style="color:#14d000">已支付</span>';
|
||||
break;
|
||||
case 'OVER':
|
||||
return '<span style="color:#ff0000">已结束</span>';
|
||||
break;
|
||||
default:
|
||||
return "未知状态";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
235
app/Models/User.php
Normal file
235
app/Models/User.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\UserPerf;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Overtrue\LaravelFollow\Traits\CanFavorite;
|
||||
use RuLong\Area\Traits\UserHasAddress;
|
||||
use RuLong\Identity\Traits\UserHasIdentity;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserAccount\Models\UserAccountLog;
|
||||
use RuLong\UserAccount\Traits\UserHasAccount;
|
||||
use RuLong\UserRelation\Traits\UserHasRelations;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable, SoftDeletes, UserHasAccount, UserHasRelations, UserHasIdentity, UserHasAddress, CanFavorite;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $info = [];
|
||||
|
||||
protected $dates = [
|
||||
'activationd_at',
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::saved(function ($model) {
|
||||
if (is_array($model->info) && !empty($model->info)) {
|
||||
$model->info()->updateOrCreate(['user_id' => $model->id], $model->info);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户资料
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:30:14+0800
|
||||
* @param array $info UserInfo fields
|
||||
*/
|
||||
protected function setInfoAttribute($info)
|
||||
{
|
||||
$this->info = $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码,留空则不修改
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-31T15:04:59+0800
|
||||
* @param void
|
||||
*/
|
||||
protected function setPasswordAttribute($password)
|
||||
{
|
||||
if ($password) {
|
||||
$this->attributes['password'] = bcrypt($password);
|
||||
}
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
return $this->hasOne(UserInfo::class);
|
||||
}
|
||||
|
||||
public function accountLogs()
|
||||
{
|
||||
return $this->hasMany(UserAccountLog::class);
|
||||
}
|
||||
|
||||
public function cashAccount()
|
||||
{
|
||||
return $this->hasOne(CashAccount::class);
|
||||
}
|
||||
|
||||
public function cashouts()
|
||||
{
|
||||
return $this->hasMany(Cashout::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的订单
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
public function cart()
|
||||
{
|
||||
return $this->hasMany(Cart::class);
|
||||
}
|
||||
|
||||
//我的提货卡
|
||||
public function mycard()
|
||||
{
|
||||
return $this->hasMany(Card::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
//使用的提货卡信息
|
||||
public function card()
|
||||
{
|
||||
return $this->hasOne(Card::class, 'active_id', 'id');
|
||||
}
|
||||
|
||||
//自己业绩
|
||||
public function selfearnings($type = 'all')
|
||||
{
|
||||
$activationd_at = $this->activationd_at;
|
||||
if (!$activationd_at) {
|
||||
return 0;
|
||||
}
|
||||
switch ($type) {
|
||||
case 'all':
|
||||
return UserPerf::where('user_id', $this->id)->where('from_id', $this->id)->where('created_at', '>=', $activationd_at)->sum('perf') ?? 0;
|
||||
break;
|
||||
case 'month':
|
||||
$between = [
|
||||
now()->startOfMonth(),
|
||||
now()->endOfMonth(),
|
||||
];
|
||||
|
||||
if ($between[0] < $activationd_at) {
|
||||
$between[0] = $activationd_at;
|
||||
}
|
||||
|
||||
return UserPerf::where('user_id', $this->id)->where('from_id', $this->id)->whereBetween('created_at', $between)->sum('perf') ?? 0;
|
||||
break;
|
||||
case 'day':
|
||||
$between = [
|
||||
now()->startOfDay(),
|
||||
now()->endOfDay(),
|
||||
];
|
||||
|
||||
if ($between[0] < $activationd_at) {
|
||||
$between[0] = $activationd_at;
|
||||
}
|
||||
|
||||
return UserPerf::where('user_id', $this->id)->where('from_id', $this->id)->whereBetween('created_at', $between)->sum('perf') ?? 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//团队收益
|
||||
public function teamearnings($type = 'all')
|
||||
{
|
||||
$activationd_at = $this->activationd_at;
|
||||
if (!$activationd_at) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'all':
|
||||
return UserPerf::where('user_id', $this->id)->where('from_id', '!=', $this->id)->where('created_at', '>=', $activationd_at)->sum('perf') ?? 0;
|
||||
break;
|
||||
case 'month':
|
||||
$between = [
|
||||
now()->startOfMonth(),
|
||||
now()->endOfMonth(),
|
||||
];
|
||||
if ($between[0] < $activationd_at) {
|
||||
$between[0] = $activationd_at;
|
||||
}
|
||||
return UserPerf::where('user_id', $this->id)->where('from_id', '!=', $this->id)->whereBetween('created_at', $between)->sum('perf') ?? 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//团队收益
|
||||
public function allearnings($type = 'all')
|
||||
{
|
||||
$activationd_at = $this->activationd_at;
|
||||
if (!$activationd_at) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'all':
|
||||
return UserPerf::where('user_id', $this->id)->where('created_at', '>=', $activationd_at)->sum('perf') ?? 0;
|
||||
break;
|
||||
case 'month':
|
||||
$between = [
|
||||
now()->startOfMonth(),
|
||||
now()->endOfMonth(),
|
||||
];
|
||||
|
||||
if ($between[0] < $activationd_at) {
|
||||
$between[0] = $activationd_at;
|
||||
}
|
||||
return UserPerf::where('user_id', $this->id)->whereBetween('created_at', $between)->sum('perf') ?? 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//获取升级金额
|
||||
public function getIdentityPrice($identity_id)
|
||||
{
|
||||
switch ($identity_id) {
|
||||
case 1:
|
||||
return config('vip_price', 399);
|
||||
break;
|
||||
case 2:
|
||||
return config('agent_price', 10000);
|
||||
break;
|
||||
case 3:
|
||||
return config('city_price', 150000);
|
||||
break;
|
||||
case 4:
|
||||
return config('shareholder_price', 300000);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTeamCountAttribute()
|
||||
{
|
||||
return $this->children()->count();
|
||||
}
|
||||
|
||||
}
|
||||
62
app/Models/UserAddress.php
Normal file
62
app/Models/UserAddress.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use RuLong\Order\Contracts\Addressbook;
|
||||
|
||||
class UserAddress extends Model implements Addressbook
|
||||
{
|
||||
/**
|
||||
* 收件人姓名
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 收件人电话
|
||||
* @return string
|
||||
*/
|
||||
public function getMobile()
|
||||
{
|
||||
return $this->mobile;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 收件人详细地址
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
if ($this->Area && $this->Area->info) {
|
||||
return str_replace(",", "-", $this->Area->info) . '-' . $this->address;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
/**
|
||||
* 收件人详细地址
|
||||
* @return string
|
||||
*/
|
||||
public function getAllAddressAttribute()
|
||||
{
|
||||
return str_replace(",", "-", $this->Area->info) . '-' . $this->address;
|
||||
|
||||
}
|
||||
|
||||
public function Area()
|
||||
{
|
||||
return $this->belongsTo(Area::class, 'area_sn', 'sn');
|
||||
}
|
||||
|
||||
public function Province()
|
||||
{
|
||||
return $this->belongsTo(Area::class, 'province_sn', 'sn');
|
||||
}
|
||||
|
||||
}
|
||||
31
app/Models/UserInfo.php
Normal file
31
app/Models/UserInfo.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\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);
|
||||
}
|
||||
|
||||
public function getHeadimgurlAttribute($value)
|
||||
{
|
||||
if ($value) {
|
||||
return $value;
|
||||
} else {
|
||||
return '/assets/index/img/head_active.png';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
10
app/Models/UserPerf.php
Normal file
10
app/Models/UserPerf.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserPerf extends Model
|
||||
{
|
||||
protected $casts = [
|
||||
'source' => 'array',
|
||||
];
|
||||
}
|
||||
30
app/Models/UserRelationLog.php
Normal file
30
app/Models/UserRelationLog.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use RuLong\Panel\Models\Admin;
|
||||
|
||||
class UserRelationLog extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function beforuser()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'before_id', 'id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(config('user_relation.user_model'));
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(config('user_relation.user_model'), 'parent_id')->withDefault();
|
||||
}
|
||||
public function operator()
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'operator_id')->withDefault();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user