Tuanzhang.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Tuanzhang extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'tuanzhang';
  9. public static function getTitle($id)
  10. {
  11. $data = self::find($id);
  12. return $data->title;
  13. }
  14. public static function getTitlebyuuid($uuid)
  15. {
  16. $data = self::where('uuid', $uuid)->find();
  17. return $data->title;
  18. }
  19. public static function getTitlebyuid($uid)
  20. {
  21. $data = self::where('uid', $uid)->find();
  22. return $data->title;
  23. }
  24. public static function getcityName($uuid)
  25. {
  26. $data = self::where('uuid', $uuid)->find();
  27. return $data->city_name;
  28. }
  29. public static function getTel($uuid)
  30. {
  31. $data = self::where('uuid', $uuid)->find();
  32. return $data->tel;
  33. }
  34. public static function conversion($vo)
  35. {
  36. $vo['cate_ids'] = Category::getmultiple($vo['cate_ids']) ?? '无';
  37. $vo['level'] = TuanzhangLevel::getTitle($vo['level']) ?? '初级';
  38. if (!empty($vo['uuid'])) {
  39. $vo['username'] = Users::getusername($vo['uuid']);
  40. }
  41. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  42. return $vo;
  43. }
  44. public static function getInfo($uuid)
  45. {
  46. $data = self::where('uuid', $uuid)->find();
  47. if (!empty($data)) {
  48. $data = $data->toArray();
  49. }
  50. return $data;
  51. }
  52. public static function getInfobyid($id)
  53. {
  54. $data = self::find($id);
  55. if (!empty($data)) {
  56. $data = $data->toArray();
  57. } else {
  58. $data = [];
  59. }
  60. return $data;
  61. }
  62. public static function getInfobyuid($uid)
  63. {
  64. $uuid = UuidRelation::getuuid($uid, 'tuanzhang');
  65. if (!empty($uuid)) {
  66. $data = Tuanzhang::where(['uuid' => $uuid])->find();
  67. if (!empty($data)) {
  68. $data = $data->toArray();
  69. } else {
  70. $data = Tuanzhang::where(['uid' => $uid])->find();
  71. if (!empty($data)) {
  72. $data = $data->toArray();
  73. if (!empty($uuid)) {
  74. Tuanzhang::where('id', $data['id'])->update(['uuid' => $uuid]);
  75. }
  76. }
  77. }
  78. }
  79. return $data;
  80. }
  81. public static function getpcarray()
  82. {
  83. $data = self::field('uuid,title')->where(['weid' => weid(), 'status' => 1])->select()->toArray();
  84. $datalist = [];
  85. foreach ($data as $key => $vo) {
  86. if (!empty($vo['uuid'])) {
  87. $datalist[$key]['val'] = $vo['uuid'];
  88. $datalist[$key]['key'] = $vo['title'];
  89. }
  90. }
  91. return $datalist;
  92. }
  93. public static function gelist_bycity($city_name)
  94. {
  95. $where['weid'] = weid();
  96. $where['status'] = 1;
  97. $where['city_name'] = $city_name;
  98. $query = Tuanzhang::where($where);
  99. $Sort = 'id desc';
  100. $data = $query->order($Sort)->select()->toArray();
  101. return $data;
  102. }
  103. public static function setIncome($order_info)
  104. {
  105. $uuid = OrderTuanzhang::getuuid($order_info['id']);
  106. if (!empty($uuid)) {
  107. $Tuanzhang = Tuanzhang::where(['uuid' => $uuid])->find();
  108. if (!empty($Tuanzhang)) {
  109. $Tuanzhang = $Tuanzhang->toArray();
  110. }
  111. if (!empty($Tuanzhang['status'])) {
  112. $percent = TuanzhangLevel::getPercent($Tuanzhang['level']);
  113. if (empty($percent)) {
  114. $percent = Config::getconfig('tuanzhang')['return_percent'];
  115. }
  116. if ($percent > 0) {
  117. if (empty($order_info['cat_id'])) {
  118. $income = OrderGoods::getCommission($order_info, 'tuanzhang', $percent);
  119. } else {
  120. $income = $order_info['total'];
  121. $income = ($income * percent_to_num($percent));
  122. }
  123. $return_percent = $percent;
  124. if ($income > 0) {
  125. if ($income > 0 && $income < 0.01) {
  126. $income = 0.01;
  127. }
  128. $TuanzhangIncomelog = TuanzhangIncomelog::where([
  129. 'uuid' => $uuid,
  130. 'weid' => $order_info['weid'],
  131. 'order_id' => $order_info['id'],
  132. ])->find();
  133. if (empty($TuanzhangIncomelog)) {
  134. Tuanzhang::where('uuid', $uuid)->inc('income', $income)->update();
  135. Tuanzhang::where('uuid', $uuid)->inc('total_income', $income)->update();
  136. Tuanzhang::where('uuid', $uuid)->inc('service_times', 1)->update();
  137. $incomedata['uuid'] = $uuid;
  138. $incomedata['ptype'] = 1;
  139. $incomedata['weid'] = $order_info['weid'];
  140. $incomedata['order_id'] = $order_info['id'];
  141. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  142. $incomedata['buyer_id'] = $order_info['uid'];
  143. $incomedata['income'] = $income;
  144. $incomedata['return_percent'] = floatval($return_percent);
  145. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  146. $incomedata['order_total'] = $order_info['total'];
  147. $incomedata['pay_time'] = $order_info['pay_time'];
  148. $incomedata['month_time'] = date('m', time());
  149. $incomedata['year_time'] = date('Y', time());
  150. $incomedata['order_status_id'] = 2; //已付款
  151. TuanzhangIncomelog::create($incomedata);
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }