Operatingcity.php 6.3 KB

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