ManyOrder.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. {
  63. $many = Many::where('id', $item['many_id'])->find();
  64. if (strtotime($item['create_time'])+1800 < time()){
  65. $user = User::where('uid', $item['uid'])->find();//用户
  66. $user1 = [];
  67. $user2 = [];
  68. if ($user['spread_uid'] > 0){
  69. $user1 = User::where('uid', $user['spread_uid'])->find();//用户
  70. if ($user1['spread_uid'] > 0) $user2 = User::where('uid', $user1['spread_uid'])->find();//用户
  71. }
  72. $purple_integral = round($item['price'] * 1.07, 2);// 奖励紫积分积分
  73. $business_integral = round($item['price'] * 0.03, 2);// 奖励商家积分
  74. $user['purple_integral'] += $purple_integral;
  75. $user['integral'] += $business_integral;
  76. if ($user1){
  77. // 直推收益的百分之十
  78. $sy1 = $item['price'] * 0.01;
  79. $user1['purple_integral'] += round($sy1 * 0.7, 2);
  80. $user1['integral'] += round($sy1 * 0.3, 2);
  81. }
  82. if ($user2){
  83. // 间推收益的百分之五
  84. $sy2 = $item['price'] * 0.005;
  85. $user2['purple_integral'] += round($sy2 * 0.7, 2);
  86. $user2['integral'] += round($sy2 * 0.3, 2);
  87. }
  88. self::where('id', $item['id'])->update(['status' => 1, 'return_time' => time()]);
  89. $user->save();
  90. UserBill::income('打怪胜利补贴紫积分', $user['uid'], 'purple_integral', 'zccg_purple_integral', $purple_integral, $user['spread_uid'], $user['purple_integral'], '打怪胜利补贴'.$many['name'].'-第'.$item['stage'].'期紫积分');
  91. UserBill::income('打怪胜利补贴商城积分', $user['uid'], 'integral', 'zccg_integral', $business_integral, $user['spread_uid'], $user['integral'], '打怪胜利补贴'.$many['name'].'-第'.$item['stage'].'期商家积分');
  92. if ($user1){
  93. UserBill::income('直推奖励紫积分', $user1['uid'], 'purple_integral', 'zccg_purple_integral', $sy1*0.7, $user1['spread_uid'], $user1['purple_integral'], '直推奖励紫积分');
  94. UserBill::income('直推奖励商城积分', $user1['uid'], 'integral', 'zccg_integral', $sy1*0.3, $user1['spread_uid'], $user1['integral'], '直推奖励商家积分');
  95. $user1->save();
  96. }
  97. if ($user2){
  98. UserBill::income('间推奖励紫积分', $user1['uid'], 'purple_integral', 'purple_integral', $sy2*0.7, $user2['spread_uid'], $user2['purple_integral'], '间推奖励紫积分');
  99. UserBill::income('间推奖励商城积分', $user1['uid'], 'integral', 'zccg_integral', $sy2*0.3, $user2['spread_uid'], $user2['integral'], '间推奖励商家积分');
  100. $user2->save();
  101. }
  102. }
  103. }
  104. }
  105. }
  106. /**
  107. * 团队奖励
  108. * @return void
  109. * @throws \think\db\exception\DataNotFoundException
  110. * @throws \think\db\exception\DbException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. */
  113. public static function push()
  114. {
  115. if (!Push::where('add_time', strtotime('today'))->find()){
  116. $user = User::select();
  117. foreach ($user as $item)
  118. {
  119. $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->where('uid', $item['uid'])->sum('price');// 昨天众筹成功返还的金额流水
  120. if ($item['spread_uid'] > 0 and $price > 0){
  121. $spread = getParent($item['uid']);// 找到所有上级
  122. $v1 = 0;
  123. $v2 = 0;
  124. $v3 = 0;
  125. $one = SystemConfig::getConfigValue('v1')/100; // v1比例
  126. $tow = SystemConfig::getConfigValue('v2')/100;// v2比例
  127. $three = SystemConfig::getConfigValue('v3')/100;// v3比例
  128. foreach ($spread as $value) {
  129. $details = User::where('uid', $value)->find();
  130. if ($details['level'] == 1){
  131. if ($v2 == 0 and $v3 == 0){
  132. // 没有发放v2和v3的奖励
  133. if ($v1 == 0) { // 没有发放v1的奖励
  134. $jl = $price * $one;
  135. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  136. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  137. $v1++;
  138. }elseif ($v1 == 1){// 发放v1奖励1次
  139. $jl = ($price*$one)*0.05;//平级的百分之五
  140. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  141. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  142. $v1++;
  143. }
  144. }
  145. }elseif ($details['level'] == 2){
  146. if ($v3 == 0){
  147. // 没有发放v3的奖励
  148. if ($v1 == 0 and $v2 == 0) { // 没有发放v1和v2的奖励的奖励
  149. $jl = $price * $tow; // 拿到流水的百分之八
  150. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  151. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  152. $v2++;
  153. }elseif($v1 == 0 and $v2 == 1) { // 没有发放v1和v2的奖励的奖励
  154. $jl = ($price * $tow)*0.05; // 拿到流水的百分之八
  155. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  156. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  157. $v2++;
  158. }elseif ($v1 > 0 and $v2 == 0){// 发放v1奖励,没有发放v2的奖励
  159. $jl = $price * ($tow - $one); // 拿到流水减掉v1的百分之五
  160. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  161. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  162. $v2++;
  163. }elseif ($v1 > 0 and $v2 == 1){// 发放v1奖励,发放v2的奖励一次
  164. $jl = ($price * ($tow - $one))*0.05; // 拿到平级的百分之五
  165. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  166. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  167. $v2++;
  168. }
  169. }
  170. }elseif ($details['level'] == 3){
  171. if ($v1 == 0 and $v2 == 0 and $v3 == 0) { // 没有发放v1和v2v3的奖励的奖励
  172. $jl = $price * $three; // 拿到流水的百分之11
  173. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  174. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  175. $v3++;
  176. }elseif ($v1 == 0 and $v2 == 0 and $v3 == 1) {// 没有发放v1和v2的奖励的奖励
  177. $jl = ($price * $three) * 0.05; // 拿到平级的百分之五
  178. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  179. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  180. $v3++;
  181. }elseif ($v1 > 0 and $v2 == 0 and $v3 == 0){// 发放v1奖励,没有发放v2v3的奖励
  182. $jl = $price * ($three - $one); // 拿到流水减掉v1的百分之五
  183. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  184. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  185. $v3++;
  186. }elseif ($v1 > 0 and $v2 == 0 and $v3 == 1){// 发放v1奖励,没有发放v2v3的奖励
  187. $jl = ($price * ($three - $one)) * 0.05; // 拿到平级的百分之五
  188. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  189. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  190. $v3++;
  191. }elseif ($v1 == 0 and $v2 > 0 and $v3 == 0){// 发放v1奖励,发放v2的奖励,没有发放v3的奖励
  192. $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
  193. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  194. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  195. $v3++;
  196. }elseif ($v1 == 0 and $v2 > 0 and $v3 == 1){// 发放v1奖励,发放v2的奖励,发放v3的奖励
  197. $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
  198. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  199. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  200. $v3++;
  201. }elseif ($v1 > 0 and $v2 > 0 and $v3 == 0){// 发放v1奖励,发放v2的奖励,发放v3的奖励
  202. $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
  203. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  204. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  205. $v3++;
  206. }elseif ($v1 > 0 and $v2 > 0 and $v3 == 1){// 发放v1奖励,发放v2的奖励,发放v3的奖励
  207. $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
  208. $details['purple_integral'] += $jl * 0.7; // 百分之70的紫积分
  209. $details['integral'] += $jl * 0.3; // 百分之30的商家积分
  210. $v3++;
  211. }
  212. }
  213. if ($jl > 0){
  214. $details->save();
  215. UserBill::income('团队奖励紫积分', $details['uid'], 'purple_integral', 'team', $jl * 0.7, 0,$details['purple_integral'], 'v'.$details['level'].'团队奖励紫积分');
  216. UserBill::income('团队奖励商城积分', $details['uid'], 'business_integral', 'team', $jl * 0.3, 0,$details['integral'], 'v'.$details['level'].'团队奖励商城积分');
  217. }
  218. $jl = 0;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. /**
  225. * 流水分红
  226. * @return void
  227. * @throws \think\db\exception\DataNotFoundException
  228. * @throws \think\db\exception\DbException
  229. * @throws \think\db\exception\ModelNotFoundException
  230. */
  231. public static function flowing_water()
  232. {
  233. if (!Push::where('add_time', strtotime('today'))->find()) {
  234. $user = User::where('flowing_water', '>', 0)->select();
  235. if ($user) {
  236. foreach ($user as $item) {
  237. $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->sum('price');// 昨天众筹成功返还的流水
  238. if ($price > 0){
  239. $details = User::where('uid', $item['uid'])->find();
  240. $details['purple_integral'] += ($price * ($details['flowing_water'] / 100)) * 0.7; // 百分之70的紫积分
  241. $details['integral'] += ($price * ($details['flowing_water'] / 100)) * 0.3; // 百分之30的商家积分
  242. $details->save();
  243. UserBill::income('分红流水奖励紫积分', $details['uid'], 'purple_integral', 'team', ($price * ($details['flowing_water'] / 100)) * 0.7, 0, $details['purple_integral'], '分红流水奖励紫积分');
  244. UserBill::income('分红流水奖励商城积分', $details['uid'], 'business_integral', 'team', ($price * ($details['flowing_water'] / 100)) * 0.3, 0, $details['business_integral'], '分红流水奖励商城积分');
  245. }
  246. }
  247. }
  248. }
  249. }
  250. /**
  251. * 更新推送时间
  252. * @return void
  253. * @throws \think\db\exception\DataNotFoundException
  254. * @throws \think\db\exception\DbException
  255. * @throws \think\db\exception\ModelNotFoundException
  256. */
  257. public static function time()
  258. {
  259. if (!Push::where('add_time', strtotime('today'))->find()) {
  260. Push::create(['add_time' => strtotime('today')]); //存入数据库信息
  261. }
  262. }
  263. }