コード例 #1
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Order::created(function ($order) {
         $status = $order->statusHistory()->create(['status' => 0, 'user_id' => $order->dispatcher_id]);
         $status->created_at = $order->created_at;
         $status->save();
         return true;
     });
     Order::updating(function ($order) {
         if ($order->isDirty('status')) {
             $order->statusHistory()->create(['status' => $order->status, 'user_id' => $order->dispatcher_id]);
         }
         return true;
     });
     view()->composer('*', function ($view) {
         $view->with('user', session('user'));
     });
 }
コード例 #2
0
ファイル: Order.php プロジェクト: unionbt/hanpaimall
        }
        $order->status = static::DEALT;
        $order->save();
        $transaction && DB::commit();
        return true;
    }
    //优惠其他
    public function bonus()
    {
        $bonus_str = "";
        if ($this->bonus_id > 0) {
            $bonus_str .= "    红包抵扣:¥" . ActivityBonus::find($this->bonus_id)->bonus;
        }
        return $bonus_str;
    }
}
Order::creating(function ($order) {
    $order->total_money = $order->details_money + $order->expresses_money;
    if (intval($order->bonus_id) > 0) {
        $bonus = ActivityBonus::find($order->bonus_id);
        $order->total_money -= $bonus->bonus;
    }
});
Order::updating(function ($order) {
    if ($order->isDirty('details_money') || $order->isDirty('expresses_money')) {
        if ($order->status != Order::INIT) {
            return false;
        }
        $order->total_money = $order->details_money + $order->expresses_money;
    }
});