Operatingcity.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 getCityid($id = '')
  26. {
  27. $mo = self::find($id);
  28. return $mo->city_id;
  29. }
  30. public static function getCityname($id = '')
  31. {
  32. $mo = self::find($id);
  33. return $mo->city_name;
  34. }
  35. public static function setIncome($order_info)
  36. {
  37. if (!empty($order_info['shipping_province_name'])) {
  38. $Operatingcity1 = self::where([
  39. 'areatype' => 1,
  40. 'status' => 1,
  41. 'province_name' => $order_info['shipping_province_name']
  42. ])->order('id asc')->select()->toArray();
  43. if (!empty($Operatingcity1)) {
  44. foreach ($Operatingcity1 as $ov1) {
  45. self::calculate($order_info, $ov1);
  46. }
  47. }
  48. }
  49. if (!empty($order_info['shipping_city_name'])) {
  50. $Operatingcity2 = self::where([
  51. 'areatype' => 2,
  52. 'status' => 1,
  53. 'city_name' => $order_info['shipping_city_name']
  54. ])->order('id asc')->select()->toArray();
  55. if (!empty($Operatingcity2)) {
  56. foreach ($Operatingcity2 as $ov2) {
  57. self::calculate($order_info, $ov2);
  58. }
  59. }
  60. }
  61. if (!empty($order_info['shipping_district_name'])) {
  62. $Operatingcity3 = self::where([
  63. 'areatype' => 3,
  64. 'status' => 1,
  65. 'district_name' => $order_info['shipping_district_name']
  66. ])->order('id asc')->select()->toArray();
  67. if (!empty($Operatingcity3)) {
  68. foreach ($Operatingcity3 as $ov3) {
  69. self::calculate($order_info, $ov3);
  70. }
  71. }
  72. }
  73. }
  74. public static function calculate($order_info, $Operatingcity)
  75. {
  76. if (!empty($Operatingcity['status'])) {
  77. $roletype = 'district';
  78. if ($Operatingcity['areatype'] == 1) {
  79. $roletype = 'province';
  80. }
  81. if ($Operatingcity['areatype'] == 2) {
  82. $roletype = 'city';
  83. }
  84. $percent = OperatingcityLevel::getPercent($Operatingcity['level']);
  85. if (empty($percent)) {
  86. $percent = Config::getconfig('operatingcity')['return_percent'];
  87. }
  88. if ($percent > 0) {
  89. if (empty($order_info['cat_id'])) {
  90. $income = OrderGoods::getCommission($order_info, $roletype, $percent);
  91. } else {
  92. $income = $order_info['total'];
  93. $income = ($income * percent_to_num($percent));
  94. }
  95. $return_percent = $percent;
  96. if ($income > 0) {
  97. if ($income > 0 && $income < 0.01) {
  98. $income = 0.01;
  99. }
  100. $OperatingcityIncomelog = OperatingcityIncomelog::where([
  101. 'ocid' => $Operatingcity['id'],
  102. 'areatype' => $Operatingcity['areatype'],
  103. 'weid' => $order_info['weid'],
  104. 'order_id' => $order_info['id'],
  105. ])->find();
  106. if (empty($OperatingcityIncomelog)) {
  107. Operatingcity::where('id', $Operatingcity['id'])->inc('income', $income)->update();
  108. Operatingcity::where('id', $Operatingcity['id'])->inc('total_income', $income)->update();
  109. $incomedata['ocid'] = $Operatingcity['id'];
  110. $incomedata['ptype'] = 1;
  111. $incomedata['areatype'] = $Operatingcity['areatype'];
  112. $incomedata['weid'] = $order_info['weid'];
  113. $incomedata['order_id'] = $order_info['id'];
  114. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  115. $incomedata['buyer_id'] = $order_info['uid'];
  116. $incomedata['income'] = $income;
  117. $incomedata['return_percent'] = floatval($return_percent);
  118. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  119. $incomedata['order_total'] = $order_info['total'];
  120. $incomedata['pay_time'] = $order_info['pay_time'];
  121. $incomedata['month_time'] = date('m', time());
  122. $incomedata['year_time'] = date('Y', time());
  123. $incomedata['order_status_id'] = 2; //已付款
  124. OperatingcityIncomelog::create($incomedata);
  125. }
  126. }
  127. }
  128. }
  129. }
  130. public static function getsettings($id)
  131. {
  132. $res = Operatingcity::find($id);
  133. if ($res) {
  134. $res = $res->toArray();
  135. $settings = unserialize($res['settings']);
  136. } else {
  137. $settings = [];
  138. }
  139. return $settings;
  140. }
  141. }