OrderRepository.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2018/12/6
  6. * Time: 11:22
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Order;
  10. use Prettus\Repository\Criteria\RequestCriteria;
  11. use Prettus\Repository\Eloquent\BaseRepository;
  12. class OrderRepository extends BaseRepository
  13. {
  14. public function model()
  15. {
  16. return Order::class;
  17. }
  18. public function boot()
  19. {
  20. $this->pushCriteria(app(RequestCriteria::class));
  21. }
  22. /**创建订单
  23. * @param $user
  24. * @param $order_type
  25. * @param $amount
  26. * @param $pay_amount
  27. * @param $pay_points
  28. * @param $service_name
  29. * @param $payment
  30. * @param $payment_cn
  31. * @param $description
  32. * @param int $is_paid
  33. * @param float $points
  34. * @param int $setmeal
  35. * @param int $payment_time
  36. * @param string $params
  37. * @param string $discount
  38. * @param string $notes
  39. * @return Order
  40. */
  41. public function addOrder($user, $order_type, $amount, $pay_amount, $pay_points, $service_name, $payment, $payment_cn, $description, $is_paid = 1, $points = 0, $setmeal = 0, $payment_time = 0, $params = '', $discount = '', $notes = '')
  42. {
  43. $data = new Order();
  44. $uid = $user->id;
  45. $data->uid = $uid;
  46. $data->utype = $user->utype;
  47. $data->order_type = $order_type;
  48. if ($pay_amount>0 && $pay_points>0) {
  49. $data->pay_type =3;
  50. } elseif ($pay_amount>0) {
  51. $data->pay_type =2;
  52. } else {
  53. $data->pay_type =1;
  54. }
  55. $data->is_pay =$is_paid;
  56. $data->amount =$amount;
  57. $data->pay_amount =$pay_amount;
  58. $data->pay_points =$pay_points;
  59. $data->payment =$payment;
  60. $data->payment_cn =$payment_cn;
  61. $data->description =$description;
  62. $data->service_name =$service_name;
  63. $data->points =$points;
  64. $data->setmeal =$setmeal;
  65. $data->params =$params;
  66. $data->notes =$notes;
  67. $data->payment_time =$payment_time;
  68. $data->discount =$discount;
  69. if ($payment == 'points') {
  70. $data->fee = 0;
  71. } else {
  72. $data->fee =$pay_amount*config("aix.system.pay.$payment.fee")/100;
  73. }
  74. $data->save();
  75. return $data;
  76. }
  77. /**
  78. * @param $oid
  79. * @return mixed
  80. */
  81. public function getOneOder($oid)
  82. {
  83. return $this->model->where('oid', $oid)->first();
  84. }
  85. public function getOrder($where){
  86. return $this->model->where($where)->first();
  87. }
  88. public function updateStatus($oid, $data)
  89. {
  90. return $this->model->where('oid', $oid)->update($data);
  91. }
  92. public function orderList($map, $where)
  93. {
  94. return $this->model->where($map)->whereIn('order_type', $where)->orderBy('created_at', 'desc')->paginate(10);
  95. }
  96. public function canselOrder()
  97. {
  98. return $this->model->where(['is_pay'=>1])->where('created_at','<',date('Y-m-d H:i:s',time()-300))->get()->toArray();
  99. }
  100. }