OrderPack.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-10-2
  6. * Time: 下午10:57
  7. */
  8. namespace App\Models;
  9. class OrderPack extends BaseModel
  10. {
  11. public function team()
  12. {
  13. return $this->belongsTo(Team::class);
  14. }
  15. public function order()
  16. {
  17. return $this->belongsTo(Order::class);
  18. }
  19. public function user(){
  20. return $this->belongsTo(User::class);
  21. }
  22. public static function checkUserServicePack($order_pack_id, $user_id, $product_type, $payment_amount)
  23. {
  24. $data = self::where('id', $order_pack_id)->where('user_id', $user_id)->first();
  25. if (empty($data)) {
  26. exit_out(null, 10001, '服务包不存在');
  27. }
  28. if ($data['end_time'] < time()) {
  29. exit_out(null, 10002, '服务包已过期');
  30. }
  31. if ($product_type == 1) {
  32. if ($data['phone_minutes'] < 10) {
  33. exit_out(null, 10003, '服务包的电话咨询时间不足');
  34. }
  35. }
  36. elseif ($product_type == 2) {
  37. if ($data['chat_num'] <= 0) {
  38. exit_out(null, 10004, '服务包的图文咨询次数不足');
  39. }
  40. }
  41. elseif ($product_type == 3) {
  42. if ($data['appoint_num'] <= 0) {
  43. exit_out(null, 10005, '服务包的门诊预约次数不足');
  44. }
  45. }
  46. elseif ($product_type == 4) {
  47. if ($data['vaccine_limit_amount'] < $payment_amount) {
  48. exit_out(null, 10006, '服务包疫苗金额不足');
  49. }
  50. }
  51. elseif ($product_type == 5) {
  52. if ($data['nurses_limit_amount'] < $payment_amount) {
  53. exit_out(null, 10007, '服务包儿保金额不足');
  54. }
  55. }
  56. return true;
  57. }
  58. public static function deductPackData($order_pack_id, $product_type, $payment_amount)
  59. {
  60. if ($product_type == 1) {
  61. self::where('id', $order_pack_id)->decrement('phone_minutes', 10);
  62. }
  63. elseif ($product_type == 2) {
  64. self::where('id', $order_pack_id)->decrement('chat_num');
  65. }
  66. elseif ($product_type == 3) {
  67. self::where('id', $order_pack_id)->decrement('appoint_num');
  68. }
  69. elseif ($product_type == 4) {
  70. self::where('id', $order_pack_id)->decrement('vaccine_limit_amount', $payment_amount);
  71. }
  72. elseif ($product_type == 5) {
  73. self::where('id', $order_pack_id)->decrement('nurses_limit_amount', $payment_amount);
  74. }
  75. return true;
  76. }
  77. }