Hospital.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Hospital extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'hospital';
  9. public static function getTitle($id = '')
  10. {
  11. $mo = self::find($id);
  12. return $mo->title;
  13. }
  14. public static function getUuid($id = '')
  15. {
  16. $mo = self::find($id);
  17. return $mo->uuid;
  18. }
  19. public static function getTitlebyuid($uuid = '')
  20. {
  21. $mo = self::where('uuid', $uuid)->find();
  22. return $mo->title;
  23. }
  24. public static function getpcarray()
  25. {
  26. $data = self::field('id,title')->where(['weid' => weid(), 'status' => 1])
  27. ->order('sort asc')
  28. ->select()->toArray();
  29. foreach ($data as $k => $v) {
  30. $array[$k]['val'] = $v['id'];
  31. $array[$k]['key'] = $v['title'];
  32. }
  33. return $array;
  34. }
  35. public static function conversion($vo)
  36. {
  37. if (empty($vo['cid'])) {
  38. $vo['cid'] = '未设置';
  39. } else {
  40. $vo['cid'] = HospitalCate::getTitle($vo['cid']);
  41. }
  42. if ($vo['end_time'] == 0) {
  43. $vo['end_time'] = '永久有效';
  44. } else {
  45. $vo['end_time'] = time_format($vo['end_time']);
  46. }
  47. $vo['cate_ids'] = Category::getmultiple($vo['cate_ids']) ?? '无';
  48. if (!empty($vo['uuid'])) {
  49. $vo['username'] = Users::getusername($vo['uuid']);
  50. }
  51. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  52. return $vo;
  53. }
  54. public static function setIncome($order_info)
  55. {
  56. if (empty($order_info['hid'])) {
  57. $uid = OrderStaff::getuuid($order_info['id']);
  58. if (!empty($uuid)) {
  59. $data = Technical::where('uuid', $uuid)->find();
  60. if (!empty($data)) {
  61. $order_info['hid'] = $data->hid;
  62. }
  63. }
  64. }
  65. if (!empty($order_info['hid'])) {
  66. $Hospital = Hospital::find($order_info['hid']);
  67. if (!empty($Hospital)) {
  68. $Hospital = $Hospital->toArray();
  69. }
  70. if (!empty($Hospital['status'])) {
  71. $percent = HospitalCate::getPercent($Hospital['cid']);
  72. if (empty($percent)) {
  73. $percent = Config::getconfig('store')['return_percent'];
  74. }
  75. if ((int)$percent > 0) {
  76. $income = ($order_info['total'] * percent_to_num($percent));
  77. $return_percent = $percent;
  78. if ($income > 0 && $income < 0.01) {
  79. $income = 0.01;
  80. }
  81. Hospital::where('id', $order_info['hid'])->inc('income', $income)->update();
  82. Hospital::where('id', $order_info['hid'])->inc('total_income', $income)->update();
  83. $incomedata['hid'] = $order_info['hid'];
  84. $incomedata['ptype'] = 1;
  85. $incomedata['weid'] = weid();
  86. $incomedata['order_id'] = $order_info['id'];
  87. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  88. $incomedata['buyer_id'] = $order_info['uid'];
  89. $incomedata['income'] = $income;
  90. $incomedata['return_percent'] = floatval($return_percent);
  91. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  92. $incomedata['order_total'] = $order_info['total'];
  93. $incomedata['pay_time'] = $order_info['pay_time'];
  94. $incomedata['month_time'] = date('m', time());
  95. $incomedata['year_time'] = date('Y', time());
  96. $incomedata['order_status_id'] = 2; //已付款
  97. StoreIncomelog::create($incomedata);
  98. }
  99. }
  100. }
  101. }
  102. }