ManyOrder.php 15 KB

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