Order.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-9-30
  6. * Time: 下午10:56
  7. */
  8. namespace App\Models;
  9. class Order extends BaseModel
  10. {
  11. CONST UNPAID = 1, ISING = 2, FINISHED = 3,CANCELED=4; //订单状态(1.未支付 2.进行中 3.已完成 4.已取消)
  12. public static $_order_status = [
  13. self::UNPAID=>'未支付',
  14. self::ISING=>'进行中',
  15. self::FINISHED=>'已完成',
  16. self::CANCELED=>'已取消',
  17. ];
  18. //获取订单状态
  19. public function getStatus()
  20. {
  21. return self::$_order_status;
  22. }
  23. public function docter()
  24. {
  25. return $this->belongsTo(Docter::class);
  26. }
  27. public function orderPatient()
  28. {
  29. return $this->hasOne(OrderPatient::class);
  30. }
  31. public function orderPack()
  32. {
  33. return $this->hasMany(OrderPack::class);
  34. }
  35. public function orderNurse()
  36. {
  37. return $this->hasMany(OrderNurse::class);
  38. }
  39. public function orderVaccine()
  40. {
  41. return $this->hasOne(OrderVaccine::class);
  42. }
  43. public function orderUser()
  44. {
  45. return $this->hasOne(User::class,'id','user_id');
  46. }
  47. public function organization()
  48. {
  49. return $this->belongsTo(Organization::class);
  50. }
  51. //支付完成的处理方法
  52. public static function payCompletedHandle($order_id)
  53. {
  54. $order = Order::select(['user_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount'])->where('id', $order_id)->first();
  55. //发送下单消息
  56. if ($order['product_type'] < 6) {
  57. $product_type_text = config('config.product_type_map')[$order['product_type']];
  58. UserMessage::saveMessage($order['user_id'], 4, $order_id, [$product_type_text]);
  59. }
  60. elseif ($order['product_type'] == 6) {
  61. $orderPack = OrderPack::select(['pack_name', 'end_time'])->where('order_id', $order_id)->first();
  62. UserMessage::saveMessage($order['user_id'], 5, $order_id, [$orderPack['pack_name'], date('Y-m-d', $orderPack['end_time'])]);
  63. }
  64. elseif ($order['product_type'] == 7) {
  65. $user = User::select(['balance'])->where('id', $order['user_id'])->first();
  66. UserMessage::saveMessage($order['user_id'], 7, $order_id, [round($order['total_amount']/100, 2), round($user['balance']/100, 2)]);
  67. }
  68. //发送余额付款成功消息
  69. if ($order['payment_type'] == 2) {
  70. $user = User::select(['balance'])->where('id', $order['user_id'])->first();
  71. UserMessage::saveMessage($order['user_id'], 8, $order_id, [round($order['payment_amount']/100, 2), round($user['balance']/100, 2)]);
  72. }
  73. return true;
  74. }
  75. }