小程序用户改用门店登录
This commit is contained in:
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 小程序购物车模型(门店订货车:按用户归属,同商品唯一行、加购合并数量)
|
||||
* 小程序购物车模型(门店订货车:按门店归属,同商品唯一行、加购合并数量)
|
||||
*/
|
||||
class CartModel extends Model
|
||||
{
|
||||
@@ -17,23 +17,23 @@ class CartModel extends Model
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'store_id',
|
||||
'product_id',
|
||||
'quantity',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'integer',
|
||||
'store_id' => 'integer',
|
||||
'product_id' => 'integer',
|
||||
'quantity' => 'decimal:2',
|
||||
];
|
||||
|
||||
/**
|
||||
* 归属用户
|
||||
* 归属门店
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
public function store(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserModel::class, 'user_id', 'id');
|
||||
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 通知模型(小程序端消息:订单 / 价格变更 / 系统;user_id=0 为全员广播)
|
||||
* 通知模型(小程序端消息:订单 / 价格变更 / 系统;store_id=0 为全员广播)
|
||||
*/
|
||||
class NoticeModel extends Model
|
||||
{
|
||||
@@ -22,14 +22,14 @@ class NoticeModel extends Model
|
||||
/** 已读 */
|
||||
public const READ = 1;
|
||||
|
||||
/** 全员广播时的 user_id 约定值 */
|
||||
public const BROADCAST_USER_ID = 0;
|
||||
/** 全员广播时的 store_id 约定值 */
|
||||
public const BROADCAST_STORE_ID = 0;
|
||||
|
||||
protected $table = 'notice';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'store_id',
|
||||
'type',
|
||||
'title',
|
||||
'content',
|
||||
@@ -41,15 +41,15 @@ class NoticeModel extends Model
|
||||
protected $casts = [
|
||||
'data' => 'array',
|
||||
'is_read' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'store_id' => 'integer',
|
||||
'read_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 接收用户(user_id=0 表示全员广播,无对应用户)
|
||||
* 接收门店(store_id=0 表示全员广播,无对应门店)
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
public function store(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserModel::class, 'user_id', 'id');
|
||||
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ class PaymentModel extends Model
|
||||
protected $fillable = [
|
||||
'payment_no',
|
||||
'store_id',
|
||||
'user_id',
|
||||
'amount',
|
||||
'pay_method',
|
||||
'voucher_ids',
|
||||
@@ -64,7 +63,6 @@ class PaymentModel extends Model
|
||||
|
||||
protected $casts = [
|
||||
'store_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'amount' => 'decimal:2',
|
||||
'pay_method' => 'integer',
|
||||
'status' => 'integer',
|
||||
@@ -124,14 +122,6 @@ class PaymentModel extends Model
|
||||
return $this->hasMany(BillModel::class, 'payment_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交人(小程序用户)
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserModel::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核人(后台系统用户)
|
||||
*/
|
||||
|
||||
+33
-12
@@ -3,17 +3,19 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
/**
|
||||
* 门店模型(小程序下单主体)
|
||||
* 门店模型(小程序下单主体,即客户;门店即用户,账号密码登录)
|
||||
*/
|
||||
class StoreModel extends Model
|
||||
class StoreModel extends Authenticatable
|
||||
{
|
||||
use SoftDeletes, HasFactory;
|
||||
use HasApiTokens, SoftDeletes, HasFactory, Notifiable;
|
||||
|
||||
/** 状态:停用 */
|
||||
public const STATUS_DISABLED = 0;
|
||||
@@ -26,6 +28,10 @@ class StoreModel extends Model
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'username',
|
||||
'password',
|
||||
'avatar',
|
||||
'last_login_at',
|
||||
'level_id',
|
||||
'contact',
|
||||
'phone',
|
||||
@@ -35,11 +41,18 @@ class StoreModel extends Model
|
||||
'remark',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'level_id' => 'integer',
|
||||
'payment_cycle_days' => 'integer',
|
||||
'total_purchase_amount' => 'decimal:2',
|
||||
'status' => 'integer',
|
||||
'last_login_at' => 'datetime:Y-m-d H:i:s',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -58,14 +71,6 @@ class StoreModel extends Model
|
||||
return $this->hasMany(StoreOrderModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定本门店的小程序用户
|
||||
*/
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店账单(采购单完成后按门店生成)
|
||||
*/
|
||||
@@ -73,4 +78,20 @@ class StoreModel extends Model
|
||||
{
|
||||
return $this->hasMany(BillModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店购物车
|
||||
*/
|
||||
public function carts(): HasMany
|
||||
{
|
||||
return $this->hasMany(CartModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店通知
|
||||
*/
|
||||
public function notices(): HasMany
|
||||
{
|
||||
return $this->hasMany(NoticeModel::class, 'store_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +43,4 @@ class SupplierModel extends Model
|
||||
{
|
||||
return $this->hasMany(ProductModel::class, 'supplier_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定本供应商的小程序用户
|
||||
*/
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserModel::class, 'supplier_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
/**
|
||||
* APP 用户模型(小程序端:门店 / 供应商用户)
|
||||
*/
|
||||
class UserModel extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/** 状态:停用 */
|
||||
public const int STATUS_DISABLED = 0;
|
||||
/** 状态:正常 */
|
||||
public const int STATUS_NORMAL = 1;
|
||||
|
||||
protected $table = 'user';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'email',
|
||||
'password',
|
||||
'nickname',
|
||||
'openid',
|
||||
'unionid',
|
||||
'phone',
|
||||
'avatar',
|
||||
'store_id',
|
||||
'status',
|
||||
'last_login_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime:Y-m-d H:i:s',
|
||||
'last_login_at' => 'datetime:Y-m-d H:i:s',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'store_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联门店
|
||||
*/
|
||||
public function store(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
||||
}
|
||||
/**
|
||||
* 用户通知
|
||||
*/
|
||||
public function notices(): HasMany
|
||||
{
|
||||
return $this->hasMany(NoticeModel::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user