XcxOrder.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Modules\Xcx\Models;
  3. use DB;
  4. use Illuminate\Database\Eloquent\Model;
  5. class XcxOrder extends Model
  6. {
  7. protected $table = 'xcx_orders';
  8. protected $fillable = [
  9. 'distribution_channel_id',
  10. 'uid',
  11. 'product_id',
  12. 'price',
  13. 'status',
  14. 'pay_type',
  15. 'trade_no',
  16. 'pay_merchant_source',
  17. 'pay_merchant_id',
  18. 'transaction_id',
  19. 'pay_end_at',
  20. 'create_ip',
  21. 'send_order_id',
  22. 'send_order_name',
  23. 'order_type',
  24. 'from_bid',
  25. 'from_type',
  26. 'activity_id'
  27. ];
  28. public static function getTotalChargeAmount($sendOrderId, $distribution_channel_id)
  29. {
  30. $totalChargeAmount = self::where(['distribution_channel_id' => $distribution_channel_id, 'send_order_id' => $sendOrderId, 'status' => 'PAID'])
  31. ->select(DB::raw(" sum(price) as totalChargeAmount "))->first();
  32. return isset($totalChargeAmount->totalChargeAmount) ? $totalChargeAmount->totalChargeAmount : '0';
  33. }
  34. public static function getTotalOrderNum($sendOrderId, $distribution_channel_id)
  35. {
  36. return self::where(['distribution_channel_id' => $distribution_channel_id, 'send_order_id' => $sendOrderId])->count();
  37. }
  38. public static function getSucOrderNum($sendOrderId, $distribution_channel_id)
  39. {
  40. return self::where(['distribution_channel_id' => $distribution_channel_id, 'send_order_id' => $sendOrderId, 'status' => 'PAID'])->count();
  41. }
  42. static function save_order($data)
  43. {
  44. return self::firstOrCreate($data);
  45. }
  46. public static function getDistributionTodayChargeAmount($distribution_channel_id)
  47. {
  48. $today = date('Y-m-d');
  49. $totalChargeAmount = self::where(['distribution_channel_id' => $distribution_channel_id, 'status' => 'PAID'])
  50. ->where('created_at', '>=', $today)
  51. ->select(DB::raw(" sum(price) as totalChargeAmount "))->first();
  52. return isset($totalChargeAmount->totalChargeAmount) ? $totalChargeAmount->totalChargeAmount : '0';
  53. }
  54. public static function getDistributionTotalChargeAmount($distribution_channel_id)
  55. {
  56. $today = date('Y-m-d');
  57. $totalChargeAmount = self::where(['distribution_channel_id' => $distribution_channel_id, 'status' => 'PAID'])
  58. ->select(DB::raw(" sum(price) as totalChargeAmount "))->first();
  59. return isset($totalChargeAmount->totalChargeAmount) ? $totalChargeAmount->totalChargeAmount : '0';
  60. }
  61. }