Tuanzhang.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. $vo = RegisterField::conversion($vo);
  43. return $vo;
  44. }
  45. public static function getInfo($uuid)
  46. {
  47. $data = self::where('uuid', $uuid)->find();
  48. if (!empty($data)) {
  49. $data = $data->toArray();
  50. }
  51. return $data;
  52. }
  53. public static function getInfobyid($id)
  54. {
  55. $data = self::find($id);
  56. if (!empty($data)) {
  57. $data = $data->toArray();
  58. } else {
  59. $data = [];
  60. }
  61. return $data;
  62. }
  63. public static function getInfobyuid($uid)
  64. {
  65. $uuid = UuidRelation::getuuid($uid, 'tuanzhang');
  66. if (!empty($uuid)) {
  67. $data = Tuanzhang::where(['uuid' => $uuid])->find();
  68. if (!empty($data)) {
  69. $data = $data->toArray();
  70. } else {
  71. $data = Tuanzhang::where(['uid' => $uid])->find();
  72. if (!empty($data)) {
  73. $data = $data->toArray();
  74. if (!empty($uuid)) {
  75. Tuanzhang::where('id', $data['id'])->update(['uuid' => $uuid]);
  76. }
  77. }
  78. }
  79. }
  80. return $data;
  81. }
  82. public static function getpcarray()
  83. {
  84. $data = self::field('uuid,title')->where(['weid' => weid(), 'status' => 1])->select()->toArray();
  85. $datalist = [];
  86. foreach ($data as $key => $vo) {
  87. if (!empty($vo['uuid'])) {
  88. $datalist[$key]['val'] = $vo['uuid'];
  89. $datalist[$key]['key'] = $vo['title'];
  90. }
  91. }
  92. return $datalist;
  93. }
  94. public static function gelist_bycity($city_name)
  95. {
  96. $where['weid'] = weid();
  97. $where['status'] = 1;
  98. $where['city_name'] = $city_name;
  99. $query = Tuanzhang::where($where);
  100. $Sort = 'id desc';
  101. $data = $query->order($Sort)->select()->toArray();
  102. return $data;
  103. }
  104. public static function setIncome($order_info)
  105. {
  106. $uuid = OrderTuanzhang::getuuid($order_info['id']);
  107. if (!empty($uuid)) {
  108. $Tuanzhang = Tuanzhang::where(['uuid' => $uuid])->find();
  109. if (!empty($Tuanzhang)) {
  110. $Tuanzhang = $Tuanzhang->toArray();
  111. }
  112. if (!empty($Tuanzhang['status'])) {
  113. $percent = TuanzhangLevel::getPercent($Tuanzhang['level']);
  114. if (empty($percent)) {
  115. $percent = Config::getconfig('tuanzhang')['return_percent'];
  116. }
  117. if ($percent > 0) {
  118. if (empty($order_info['cat_id'])) {
  119. $income = OrderGoods::getCommission($order_info, 'tuanzhang', $percent);
  120. } else {
  121. $income = $order_info['total'];
  122. $income = ($income * percent_to_num($percent));
  123. }
  124. $return_percent = $percent;
  125. if ($income > 0) {
  126. if ($income > 0 && $income < 0.01) {
  127. $income = 0.01;
  128. }
  129. $TuanzhangIncomelog = TuanzhangIncomelog::where([
  130. 'uuid' => $uuid,
  131. 'weid' => $order_info['weid'],
  132. 'order_id' => $order_info['id'],
  133. ])->find();
  134. if (empty($TuanzhangIncomelog)) {
  135. Tuanzhang::where('uuid', $uuid)->inc('income', $income)->update();
  136. Tuanzhang::where('uuid', $uuid)->inc('total_income', $income)->update();
  137. Tuanzhang::where('uuid', $uuid)->inc('service_times', 1)->update();
  138. $incomedata['uuid'] = $uuid;
  139. $incomedata['ptype'] = 1;
  140. $incomedata['weid'] = $order_info['weid'];
  141. $incomedata['order_id'] = $order_info['id'];
  142. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  143. $incomedata['buyer_id'] = $order_info['uid'];
  144. $incomedata['income'] = $income;
  145. $incomedata['return_percent'] = floatval($return_percent);
  146. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  147. $incomedata['order_total'] = $order_info['total'];
  148. $incomedata['pay_time'] = $order_info['pay_time'];
  149. $incomedata['month_time'] = date('m', time());
  150. $incomedata['year_time'] = date('Y', time());
  151. $incomedata['order_status_id'] = 2; //已付款
  152. TuanzhangIncomelog::create($incomedata);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }