ManyOrder.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/11
  5. */
  6. namespace app\models\many;
  7. use app\admin\model\system\SystemConfig;
  8. use app\models\user\User;
  9. use app\models\user\UserBill;
  10. use crmeb\services\PHPExcelService;
  11. use crmeb\traits\ModelTrait;
  12. use crmeb\basic\BaseModel;
  13. /**
  14. * Class StoreCategory
  15. * @package app\admin\model\store
  16. */
  17. class ManyOrder extends BaseModel
  18. {
  19. /**
  20. * 数据表主键
  21. * @var string
  22. */
  23. protected $pk = 'id';
  24. /**
  25. * 模型名称
  26. * @var string
  27. */
  28. protected $name = 'many_order';
  29. use ModelTrait;
  30. protected $autoWriteTimestamp = true;
  31. public static function list($where)
  32. {
  33. $model = self::alias('a')
  34. ->order('a.id DESC')
  35. ->field('a.*,b.name,u.nickname')
  36. ->leftJoin('many b', 'b.id = a.many_id')
  37. ->leftJoin('user u', 'u.uid = a.uid')
  38. ->where('a.uid', $where['uid']);
  39. // if ($where['status'] == 0 or $where['status']) $model->where('a.status', '=', $where['status']);
  40. $data['count'] = $model->count();
  41. if ($where['page'] && $where['limit']) {
  42. $model->page($where['page'], $where['limit']);
  43. } else {
  44. $model->page(20, 1);
  45. }
  46. $list = $model->select()->toArray();
  47. $data['data'] = $list;
  48. return $data;
  49. }
  50. /**
  51. * 众筹成功订单返还
  52. * @return void
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public static function suc_return()
  58. {
  59. $order = self::where('is_return', 1)->where('status', 0)->select(); // 查询需要返还的订单
  60. if ($order) {
  61. foreach ($order as $item) {
  62. $many = Many::where('id', $item['many_id'])->find();
  63. $user = User::where('uid', $item['uid'])->find();//用户
  64. $user1 = [];
  65. $user2 = [];
  66. if ($user['spread_uid'] > 0) {
  67. $user1 = User::where('uid', $user['spread_uid'])->find();//用户
  68. if ($user1['spread_uid'] > 0) $user2 = User::where('uid', $user1['spread_uid'])->find();//用户
  69. }
  70. $purple_integral = round($item['price'] * 1.07, 2);// 奖励紫积分积分
  71. $business_integral = round($item['price'] * 0.03, 2);// 奖励商家积分
  72. $user['purple_integral'] += $purple_integral;
  73. $user['integral'] += $business_integral;
  74. if ($user1) {
  75. // 直推收益的百分之十
  76. $sy1 = $item['price'] * 0.01;
  77. $user1['purple_integral'] += round($sy1 * 0.7, 2);
  78. $user1['integral'] += round($sy1 * 0.3, 2);
  79. }
  80. if ($user2) {
  81. // 间推收益的百分之五
  82. $sy2 = $item['price'] * 0.005;
  83. $user2['purple_integral'] += round($sy2 * 0.7, 2);
  84. $user2['integral'] += round($sy2 * 0.3, 2);
  85. }
  86. self::where('id', $item['id'])->update(['status' => 1, 'return_time' => time()]);
  87. $user->save();
  88. UserBill::income('种树成功补贴阳光', $user['uid'], 'purple_integral', 'zccg_purple_integral', $purple_integral, $user['spread_uid'], $user['purple_integral'], '种树成功补贴' . $many['name'] . '-第' . $item['stage'] . '期阳光');
  89. UserBill::income('种树成功补贴商城积分', $user['uid'], 'integral', 'zccg_integral', $business_integral, $user['spread_uid'], $user['integral'], '种树成功补贴' . $many['name'] . '-第' . $item['stage'] . '期商家积分');
  90. if ($user1) {
  91. UserBill::income('直推奖励阳光', $user1['uid'], 'purple_integral', 'zt_purple_integral', $sy1 * 0.7, $user1['spread_uid'], $user1['purple_integral'], '直推奖励阳光');
  92. UserBill::income('直推奖励商城积分', $user1['uid'], 'integral', 'zt_integral', $sy1 * 0.3, $user1['spread_uid'], $user1['integral'], '直推奖励商家积分');
  93. $user1->save();
  94. }
  95. if ($user2) {
  96. UserBill::income('间推奖励阳光', $user1['uid'], 'purple_integral', 'jt_purple_integral', $sy2 * 0.7, $user2['spread_uid'], $user2['purple_integral'], '间推奖励阳光');
  97. UserBill::income('间推奖励商城积分', $user1['uid'], 'integral', 'jt_integral', $sy2 * 0.3, $user2['spread_uid'], $user2['integral'], '间推奖励商家积分');
  98. $user2->save();
  99. }
  100. }
  101. }
  102. }
  103. /**
  104. * 团队奖励
  105. * @return void
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\DbException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. */
  110. public static function push()
  111. {
  112. if (!Push::where('add_time', strtotime('today'))->find()) {
  113. $user = User::select();
  114. foreach ($user as $item) {
  115. $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->where('status', 1)->where('uid', $item['uid'])->sum('price');// 昨天众筹成功返还的金额流水
  116. if ($item['spread_uid'] > 0 and $price > 0) {
  117. $spread = getParent($item['uid']);// 找到所有上级
  118. $v1 = 0;
  119. $v2 = 0;
  120. $v3 = 0;
  121. $one = SystemConfig::getConfigValue('v1') / 100; // v1比例
  122. $tow = SystemConfig::getConfigValue('v2') / 100;// v2比例
  123. $three = SystemConfig::getConfigValue('v3') / 100;// v3比例
  124. foreach ($spread as $value) {
  125. $details = User::where('uid', $value)->find();
  126. if ($details['level'] == 1) {
  127. if ($v2 == 0 and $v3 == 0) {
  128. // 没有发放v2和v3的奖励
  129. if ($v1 == 0) { // 没有发放v1的奖励
  130. $jl = $price * $one;
  131. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  132. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  133. $v1++;
  134. } elseif ($v1 == 1) {// 发放v1奖励1次
  135. $jl = ($price * $one) * 0.05;//平级的百分之五
  136. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  137. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  138. $v1++;
  139. }
  140. }
  141. } elseif ($details['level'] == 2) {
  142. if ($v3 == 0) {
  143. // 没有发放v3的奖励
  144. if ($v1 == 0 and $v2 == 0) { // 没有发放v1和v2的奖励的奖励
  145. $jl = $price * $tow; // 拿到流水的百分之八
  146. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  147. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  148. $v2++;
  149. } elseif ($v1 == 0 and $v2 == 1) { // 没有发放v1和v2的奖励的奖励
  150. $jl = ($price * $tow) * 0.05; // 拿到流水的百分之八
  151. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  152. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  153. $v2++;
  154. } elseif ($v1 > 0 and $v2 == 0) {// 发放v1奖励,没有发放v2的奖励
  155. $jl = $price * ($tow - $one); // 拿到流水减掉v1的百分之五
  156. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  157. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  158. $v2++;
  159. } elseif ($v1 > 0 and $v2 == 1) {// 发放v1奖励,发放v2的奖励一次
  160. $jl = ($price * ($tow - $one)) * 0.05; // 拿到平级的百分之五
  161. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  162. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  163. $v2++;
  164. }
  165. }
  166. } elseif ($details['level'] == 3) {
  167. if ($v1 == 0 and $v2 == 0 and $v3 == 0) { // 没有发放v1和v2v3的奖励的奖励
  168. $jl = $price * $three; // 拿到流水的百分之11
  169. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  170. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  171. $v3++;
  172. } elseif ($v1 == 0 and $v2 == 0 and $v3 == 1) {// 没有发放v1和v2的奖励的奖励
  173. $jl = ($price * $three) * 0.05; // 拿到平级的百分之五
  174. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  175. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  176. $v3++;
  177. } elseif ($v1 > 0 and $v2 == 0 and $v3 == 0) {// 发放v1奖励,没有发放v2v3的奖励
  178. $jl = $price * ($three - $one); // 拿到流水减掉v1的百分之五
  179. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  180. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  181. $v3++;
  182. } elseif ($v1 > 0 and $v2 == 0 and $v3 == 1) {// 发放v1奖励,没有发放v2v3的奖励
  183. $jl = ($price * ($three - $one)) * 0.05; // 拿到平级的百分之五
  184. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  185. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  186. $v3++;
  187. } elseif ($v1 == 0 and $v2 > 0 and $v3 == 0) {// 发放v1奖励,发放v2的奖励,没有发放v3的奖励
  188. $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
  189. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  190. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  191. $v3++;
  192. } elseif ($v1 == 0 and $v2 > 0 and $v3 == 1) {// 发放v1奖励,发放v2的奖励,发放v3的奖励
  193. $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
  194. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  195. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  196. $v3++;
  197. } elseif ($v1 > 0 and $v2 > 0 and $v3 == 0) {// 发放v1奖励,发放v2的奖励,发放v3的奖励
  198. $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
  199. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  200. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  201. $v3++;
  202. } elseif ($v1 > 0 and $v2 > 0 and $v3 == 1) {// 发放v1奖励,发放v2的奖励,发放v3的奖励
  203. $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
  204. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  205. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  206. $v3++;
  207. }
  208. }
  209. if ($jl > 0) {
  210. $details->save();
  211. UserBill::income('团队奖励阳光', $details['uid'], 'purple_integral', 'td_purple_integral', $jl * 0.7, 0, $details['purple_integral'], 'v' . $details['level'] . '团队奖励阳光');
  212. UserBill::income('团队奖励商城积分', $details['uid'], 'integral', 'td_integral', $jl * 0.3, 0, $details['integral'], 'v' . $details['level'] . '团队奖励商城积分');
  213. }
  214. $jl = 0;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. /**
  221. * 流水分红
  222. * @return void
  223. * @throws \think\db\exception\DataNotFoundException
  224. * @throws \think\db\exception\DbException
  225. * @throws \think\db\exception\ModelNotFoundException
  226. */
  227. public static function flowing_water()
  228. {
  229. if (!Push::where('add_time', strtotime('today'))->find()) {
  230. $user = User::where('flowing_water', '>', 0)->select();
  231. if ($user) {
  232. foreach ($user as $item) {
  233. $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->sum('price');// 昨天众筹成功返还的流水
  234. if ($price > 0) {
  235. $details = User::where('uid', $item['uid'])->find();
  236. $details['purple_integral'] += ($price * ($details['flowing_water'] / 100)) * 0.7; // 百分之70的紫积分
  237. $details['integral'] += ($price * ($details['flowing_water'] / 100)) * 0.3; // 百分之30的商家积分
  238. $details->save();
  239. UserBill::income('分红流水奖励阳光', $details['uid'], 'purple_integral', 'team_purple_integral', ($price * ($details['flowing_water'] / 100)) * 0.7, 0, $details['purple_integral'], '分红流水奖励阳光');
  240. UserBill::income('分红流水奖励商城积分', $details['uid'], 'integral', 'team_integral', ($price * ($details['flowing_water'] / 100)) * 0.3, 0, $details['integral'], '分红流水奖励商城积分');
  241. }
  242. }
  243. }
  244. }
  245. }
  246. /**
  247. * 更新推送时间
  248. * @return void
  249. * @throws \think\db\exception\DataNotFoundException
  250. * @throws \think\db\exception\DbException
  251. * @throws \think\db\exception\ModelNotFoundException
  252. */
  253. public static function time()
  254. {
  255. if (!Push::where('add_time', strtotime('today'))->find()) {
  256. Push::create(['add_time' => strtotime('today')]); //存入数据库信息
  257. }
  258. }
  259. }