HistoryShopBuyedItem.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Models\Web;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use DB;
  6. class HistoryShopBuyedItem extends Model
  7. {
  8. protected $connection = "WEB";
  9. protected $table = "HistoryShopBuyedItem";
  10. protected $primaryKey = "ID";
  11. protected $dates = ["Created_At"];
  12. protected $fillable = ["ID","AccountDBID","LinkItemID","Count","Price","Created_At"];
  13. public $timestamps = false;
  14. public function accountinfo(){
  15. return $this->belongsTo('App\Models\Login\AccountInfo', 'AccountDBID');
  16. }
  17. public static function SaveHistory($AccountDBID, $LinkItemID, $Count, $Price)
  18. {
  19. // Inicia as transactions
  20. $history_tran = DB::connection('WEB');
  21. $history_tran->beginTransaction();
  22. try {
  23. $hitory = new HistoryShopBuyedItem;
  24. $hitory->AccountDBID = $AccountDBID;
  25. $hitory->LinkItemID = $LinkItemID;
  26. $hitory->Count = $Count;
  27. $hitory->Price = $Price;
  28. $hitory->Created_At = now();
  29. $hitory->save();
  30. // COMMIT TRAN
  31. $history_tran->commit();
  32. } catch (\Exception $e){
  33. // ROLLBACK
  34. $history_tran->rollback();
  35. throw new \Exception($e);
  36. }
  37. }
  38. }