| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- class Order extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- protected $fillable = [
- 'id',
- 'batch_id',
- 'owner_id',
- 'status',
- 'created_at',
- 'code',
- 'shop_id',
- 'client_code',
- 'logistic_id',
- 'consignee_name',
- 'consignee_phone',
- 'province',
- 'city',
- 'district',
- 'address',
- 'warehouse_id',
- 'wms_edittime',
- 'wms_status',
- 'order_type',
- 'frozen',
- 'pay_at',
- ];
- /*
- * wms订单号 code=>DOC_ORDER_HEADER[orderno]
- * wms客户订单号 client_code=>DOC_ORDER_HEADER['soreference1']
- * wms订单状态 wms_status=>
- * 仓库 warehouse_id=>DOC_ORDER_HEADER['WAREHOUSEID']
- */
- const STATUS = [
- '00' => "创建订单",
- '10' => "部分预配",
- '20' => "预配完成",
- '30' => "部分分配",
- '40' => "分配完成",
- '50' => "部分拣货",
- '60' => "拣货完成",
- '61' => "播种完成",
- '62' => "部分装箱",
- '63' => "完全装箱",
- '65' => "部分装车",
- '66' => "装车完成",
- '70' => "部分发运",
- '80' => "完全发运",
- '90' => "订单取消",
- '98' => "等待释放",
- '99' => "订单完成",
- ];
- public function cancel(){
- $this['status'] = '取消';
- $this->update();
- }
- public function logistic()
- {
- return $this->hasOne(Logistic::class, 'id', 'logistic_id');
- }
- public function issue()
- {
- return $this->belongsTo(OrderIssue::class, 'id', 'order_id');
- }
- public function shop()
- {
- return $this->belongsTo(Shop::class, 'shop_id', 'id');
- }
- public function owner()
- {
- return $this->hasOne(Owner::class, 'id', 'owner_id');
- }
- public function packages()
- {
- return $this->hasMany(OrderPackage::class,'order_id','id');
- }
- public function warehouse()
- {
- return $this->belongsTo(Warehouse::class);
- }
- public function orderCommodities(){
- return $this->hasMany('App\OrderCommodity','order_id','id');
- }
- public function bin(){
- return $this->hasOne('App\OrderBin','order_id','id');
- }
- public function batch(){
- return $this->belongsTo('App\Batch', 'batch_id','id');
- }
- public function detail(): HasOne
- {
- return $this->hasOne(OrderDetail::class);
- }
- public function getLogisticNumbersAttribute()
- {
- $packages = $this->packages;
- if (!$packages) {
- return [];
- } else {
- $arr = [];
- foreach ($packages as $package) {
- array_push($arr, $package->logistic_number);
- }
- return $arr;
- }
- }
- public function getAmountAttribute()
- {
- $packages = $this->packages;
- if (!$packages) {
- return 0;
- } else {
- $count = 0;
- foreach ($packages as $package) {
- foreach ($package->commodities as $item) {
- $count += $item->amount;
- }
- }
- return $count;
- }
- }
- public function getCommodityPackagesAttribute()
- {
- $packages = $this->packages;
- if (!$packages) {
- return 0;
- } else {
- $count = 0;
- foreach ($packages as $package) {
- foreach ($package->commodities as $item) {
- $count++;
- }
- }
- return $count;
- }
- }
- public function delete()
- {
- $this->packages()->delete();
- return parent::delete();
- }
- public function deleteSafe()
- {
- return parent::delete();
- }
- public function isEquals($order)
- {
- return $this['wms_edittime'] == $order['wms_edittime']
- && $this['batch_id'] == $order['batch_id']
- && $this['warehouse_id'] == $order['warehouse_id']
- && $this['frozen'] == $order['frozen'];
- }
- public function assignValueByOrder($order)
- {
- $this['code'] = $order['code'] ;
- $this['batch_id'] = $order['batch_id'] ;
- $this['warehouse_id'] = $order['warehouse_id'] ;
- $this['owner_id'] = $order['owner_id'] ;
- $this['shop_id'] = $order['shop_id'] ;
- $this['logistic_id'] = $order['logistic_id'] ;
- $this['consignee_name'] = $order['consignee_name'] ;
- $this['consignee_phone'] = $order['consignee_phone'] ;
- $this['province'] = $order['province'] ;
- $this['city'] = $order['city'] ;
- $this['district'] = $order['district'] ;
- $this['address'] = $order['address'] ;
- $this['client_code'] = $order['client_code'] ;
- $this['wms_status'] = $order['wms_status'] ;
- $this['wms_edittime'] = $order['wms_edittime'];
- $this['frozen'] = $order['frozen'];
- $this['order_type'] = $order['order_type'];
- $this['created_at'] =$order['created_at'];
- $this['pay_at'] =$order['pay_at'];
- }
- public static function getFrozen($string): string
- {
- $arr = [
- 'H' => '是',
- 'Y' => '否',
- 'N' => '否'
- ];
- return $arr[$string] ?? '否';
- }
- public function OracleDOCOrderHeader(): BelongsTo
- {
- return $this->belongsTo(OracleDOCOrderHeader::class,'code','orderno');
- }
- }
|