ManyOrder.php 16 KB

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