Taskorderguquan.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/28
  6. */
  7. namespace app\controller\api\store\merchant;
  8. use think\facade\Db;
  9. class Taskorderguquan
  10. {
  11. public function assignment()
  12. {
  13. $user_team_amount = Db::name("old_user_of_goods")
  14. ->select();
  15. // 计算总业绩
  16. $totalPv = [];
  17. foreach ($user_team_amount as $order) {
  18. if (!isset($totalPv[$order['user_id']])) {
  19. $totalPv[$order['user_id']] = 0;
  20. }
  21. switch ($order['money']) {
  22. case 1180:
  23. $totalPv[$order['user_id']] += 700;
  24. break;
  25. case 11800:
  26. $totalPv[$order['user_id']] += 7000;
  27. break;
  28. case 10620:
  29. $totalPv[$order['user_id']] += 6300;
  30. break;
  31. case 2360:
  32. $totalPv[$order['user_id']] += 1400;
  33. break;
  34. case 9440:
  35. $totalPv[$order['user_id']] += 5600;
  36. break;
  37. default:
  38. if ($order['money'] == 2344.99) {
  39. break;
  40. }
  41. $totalPv[$order['user_id']] += round($order['money'] * 0.7,2);
  42. break;
  43. }
  44. }
  45. foreach ($totalPv as $uid => $pv) {
  46. Db::name("user")->where('is_old', 1)->where("uid", $uid)->update(['pv' => $pv]);
  47. }
  48. return;
  49. /**
  50. * 周金花200(13959100621)
  51. * 黄金花200(18603401312)
  52. * 徐立苹100(13521438652)
  53. * 李素红200(13701061395)
  54. * 周行体200(13231658486)
  55. * 刘银霞100(13161909228)
  56. * 李卫东100(13911601230)
  57. * 金 波100(13801358713)
  58. * 王 玲 150(15810064711)
  59. * 侯玉兰150(15232797965)
  60. * 吕丽娣100(15960349667)
  61. * 张传莲100(15332507711)
  62. * 刘春梅100(18760167163)
  63. * 付天如100(18863873000)
  64. * 付绍先100(15324059286)
  65. * 黄桂林100(15960196876)
  66. * 温 煌100(18350134089)
  67. * 谭英先100(13978627072)
  68. * 陈玉珍100(19858353660)
  69. * 黄雪云100(18650055445)
  70. * 黄 玲100(13877193411)
  71. * 邱佳珍100(13960379098)
  72. * 隋彩云100(13601071082)
  73. */
  74. $data = [
  75. '13959100621' => 200,
  76. '18603401312' => 200,
  77. '13521438652' => 100,
  78. '13701061395' => 200,
  79. '13231658486' => 200,
  80. '13161909228' => 100,
  81. '13911601230' => 100,
  82. '13801358713' => 100,
  83. '15810064711' => 150,
  84. '15232797965' => 150,
  85. '15960349667' => 100,
  86. '15332507711' => 100,
  87. '18760167163' => 100,
  88. '18863873000' => 100,
  89. '15324059286' => 100,
  90. '15960196876' => 100,
  91. '18350134089' => 100,
  92. '13978627072' => 100,
  93. '19858353660' => 100,
  94. '18650055445' => 100,
  95. '13877193411' => 100,
  96. '13960379098' => 100,
  97. '13601071082' => 100,
  98. ];
  99. $result = Db::name("user")
  100. ->whereIn("account", array_keys($data))
  101. ->where('is_del', 0)
  102. ->field('uid, brokerage_price, account, nickname')
  103. ->select();
  104. $res = [];
  105. foreach ($result as $v) {
  106. Db::name("user")->where("uid", $v['uid'])->inc("brokerage_price", $data[$v['account']])->save();
  107. $this->bill_user_log111111($v['uid'], "佣金补贴", $data[$v['account']], "佣金补贴", 8);//股权分佣明细2.0系统
  108. $res[] = [
  109. 'uid' => $v['uid'],
  110. 'account' => $v['account'],
  111. 'brokerage_price_pre' => $v['brokerage_price'],
  112. 'brokerage_price' => $data[$v['account']],
  113. 'nickname' => $v['nickname']
  114. ];
  115. }
  116. return json($res);
  117. }
  118. public function lst6()
  119. {
  120. $startTime = '2025-03-10';
  121. $endTime = '2025-03-30';
  122. // 查询测试人员账号信息
  123. //18973958920
  124. //15186694339
  125. //18833633835
  126. //19525470098
  127. //17756507016
  128. //18226705337
  129. $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337'];
  130. $removeUserList = Db::name("user")
  131. ->whereIn('account', $testAccount)
  132. ->where("status", "<>", 0)
  133. ->where('is_del', '<>', 1)
  134. ->select()
  135. ->toArray();
  136. $removeUserIdList = array_column($removeUserList, 'uid');
  137. if (empty($startTime) || empty($endTime)) {
  138. $timeMap = $this->getTime('last_week');
  139. $startTime = $timeMap['startTime'] . ' 00:00:00';
  140. $endTime = $timeMap['endTime'] . ' 23:59:59';
  141. }
  142. // 定义分红金额
  143. $weekRecord = $this->getTeamPvByTime($startTime, $endTime, $removeUserIdList);
  144. // 分红金额 - 红包金额
  145. $redEnvelope = $this->getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList);
  146. $weekRecord -= $redEnvelope;
  147. if ($weekRecord <= 0) {
  148. return json('无效分红金额');
  149. }
  150. // $stock_comm = round($weekRecord * 0.05 ,2);
  151. $stock_comm = floor(($weekRecord * 0.05) * 100) / 100;
  152. //获取股权分红的人
  153. $GetAllUserPackNum = db::name("old_user_stock")->sum("pack");//计算所有用户的份数总和
  154. $stockuserdatas = db::name("old_user_stock")->select();//获取所有用户
  155. $salesArr = [];
  156. if (count($stockuserdatas) > 0) {
  157. // $one_pack_comm_data = round($stock_comm / $GetAllUserPackNum,2);//获取每份的单佣金
  158. $one_pack_comm_data = floor(($stock_comm / $GetAllUserPackNum) * 100) / 100;
  159. foreach ($stockuserdatas as &$v) {
  160. $salesArr[] = [
  161. 'stock_comm' => $stock_comm,
  162. 'GetAllUserPackNum' => $GetAllUserPackNum,
  163. 'uid' => $v['user_id'],
  164. 'pack' => $v['pack'],
  165. 'one_pack_comm_data' => $one_pack_comm_data,
  166. 'getcomm' => floor(($v['pack'] * $one_pack_comm_data) * 100) / 100
  167. ];
  168. $v['getcomm'] = floor(($v['pack'] * $one_pack_comm_data) * 100) / 100;
  169. $v['allgetcomm'] = $v['allgetcomm'] + $v['getcomm'];
  170. $v['update_time'] = time();
  171. $yj_90 = $v['getcomm'] * 0.9;
  172. $fg_10 = $v['getcomm'] * 0.1;
  173. // // 更新 user_stock 表中的记录
  174. $res = db::name("old_user_stock")->where("id", $v['id'])->update([
  175. 'getcomm' => $v['getcomm'],
  176. 'allgetcomm' => $v['allgetcomm'],
  177. 'update_time' => $v['update_time']
  178. ]);
  179. Db::name("user")->where("uid", $v['user_id'])->inc("brokerage_price", $yj_90)->save();
  180. $res1 = Db::name("user")->where("uid", $v['user_id'])->inc("total_amount_old", $yj_90)->save();
  181. $res2 = Db::name("user")->where("uid", $v['user_id'])->inc("amount_old", $yj_90)->save();
  182. $res3 = Db::name("user")->where("uid", $v['user_id'])->inc("fugou", $fg_10)->save();
  183. $res = true;
  184. if ($res) {
  185. $das = $this->change_user_log($v['user_id'], 'amount_old', 1, $yj_90, "member_award_stock", "股权分红入账" . "-" . $v['pack']);//释放佣金
  186. //入账星级分红记录表
  187. $week_data = [];
  188. $week_data['user_id'] = $v['user_id'];
  189. $week_data['user_star_id'] = 0;
  190. $week_data['award_num'] = 0;
  191. $week_data['award_num_sm'] = 0;
  192. $week_data['remark'] = "股权分红主动执行" . $yj_90;
  193. $week_data['week_record'] = $weekRecord;
  194. $week_data['all_amount'] = $stock_comm;
  195. $week_data['radio'] = 2;
  196. $week_data['owner_bill'] = 0; //总流水金额
  197. $week_data['my_bill'] = 0; //我的流水
  198. $week_data['create_time'] = time();
  199. Db::name("old_user_weekaward")->insert($week_data);
  200. $userdatassss = db::name("old_user_jbp")->where("id", $v['user_id'])->find();
  201. $datas_log = [
  202. 'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v['user_id'] . " 新增股权佣金:" . $yj_90,
  203. 'create_time' => date('Y-m-d H:i:s')
  204. ];
  205. $con_data = Db::name('test_log')->insert($datas_log); //数据存到2.0数据表中
  206. $this->bill_user_log111111($v['user_id'], "股权分佣", $yj_90, "股权明细入账", 13);//股权分佣明细2.0系统
  207. $this->fugou_user_log($v['user_id'], $fg_10, 16, 1, 1);//复购金明细入账
  208. }
  209. }
  210. }
  211. return json($salesArr);
  212. //股权分红 end
  213. }
  214. //添加复购金
  215. public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
  216. {
  217. $fugou_data = Db::name('user')->where("uid", $uid)->find();
  218. $bill = [
  219. 'uid' => $uid,
  220. 'number' => $num,//数量
  221. 'status' => $status,//复购金状态1-有效 0-失效 -1待确认
  222. 'mark' => "复购金",//备注
  223. 'desc' => "10%作为复购金",//描述
  224. 'order_id' => $order_id,//订单id
  225. 'surplus' => 0,//剩余
  226. 'order_type' => 11,//关联订单ID
  227. 'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
  228. 'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
  229. 'addtime' => time(),
  230. ];
  231. Db::name('user_sign_fugou')->insert($bill);
  232. }
  233. //添加平台分佣2.0系统收益明细日志(养老金金额)
  234. public function bill_user_log111111($uid, $name, $num, $mark, $comm)
  235. {
  236. $con_data = Db::name('user')->where("uid", $uid)->find();
  237. //如果是会员专区就即刻到账
  238. // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
  239. $bill = [
  240. 'uid' => $uid,
  241. 'link_id' => 0,//关联订单id
  242. 'pm' => 1,//0:支出,1:获得
  243. 'title' => $name,//账单标题
  244. 'category' => 'now_money',//明细种类
  245. 'type' => 'commission',//明细类型
  246. 'number' => $num,//明细数字
  247. 'balance' => 0,//剩余
  248. 'mark' => $mark,//备注
  249. 'create_time' => date('Y-m-d H:i:s'),//添加时间
  250. 'status' => 1,//0待确定,1有效,-1无效
  251. 'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
  252. //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
  253. //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
  254. 'order_sn' => 0,//订单号
  255. 'tripartite' => 0,//
  256. 'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
  257. 'mer_id' => 0,//商户id
  258. 'source' => 0,//1线下 0线上
  259. 'order_type' => 1,//1自营 2 第三方 订单类型
  260. 'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
  261. 'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
  262. 'take_time' => '',//结算时间
  263. 'district_id' => '',//
  264. 'street_id' => '',//
  265. 'month' => '',//月份
  266. ];
  267. Db::name('user_bill')->insert($bill);
  268. }
  269. //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金
  270. function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
  271. {
  272. $transition = [
  273. 'pv' => 1,
  274. "gb" => 2,
  275. "df" => 3,
  276. "vr" => 4,
  277. "bt" => 5,
  278. "withdraw_quota_old" => 6,//提现
  279. "unsettled_pension" => 7,
  280. "amount_old" => 8//发放佣金
  281. ];
  282. $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
  283. if (empty($routineInfo)) {
  284. return false;
  285. }
  286. $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
  287. if ($appoint_money > 0) {
  288. $alter_money = $appoint_money;
  289. } else {
  290. //再去查询变更前的 金额
  291. $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
  292. }
  293. if ($change_status == 1) {
  294. //新增前
  295. $alter_money = $alter_money - $money;
  296. } else if ($change_status == 2) {
  297. //减少前
  298. $alter_money = $alter_money + $money;
  299. }
  300. if ($alter_money < 0) {
  301. $alter_money = 0;
  302. }
  303. $inser_data = [];
  304. $inser_data['user_id'] = $user_id;
  305. $inser_data['type'] = $transition[$type];
  306. $inser_data['change_status'] = $change_status;
  307. $inser_data['money'] = $money;
  308. $inser_data['routine_log_of_key_id'] = $key_id;
  309. $inser_data['remark'] = $remark;
  310. $inser_data['is_admin'] = $is_admin;
  311. $inser_data['create_time'] = time();
  312. $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
  313. Db::name("old_user_log")->insert($inser_data);
  314. }
  315. public function getTime($timePeriod)
  316. {
  317. // 定义时间区间
  318. $now = time();
  319. $startTime = '';
  320. $endTime = '';
  321. if ($timePeriod == 'last_week') {
  322. // 上周的时间区间
  323. $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
  324. $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
  325. } elseif ($timePeriod == 'this_week') {
  326. // 这周的时间区间
  327. $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
  328. $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
  329. }
  330. // return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
  331. return ['startTime' => $startTime, 'endTime' => $endTime];
  332. }
  333. public function getTeamPvByTime($startTime, $endTime, $removeUserIdList = [])
  334. {
  335. // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
  336. $orders = Db::name("store_order")
  337. ->where('mer_id', 496)
  338. ->whereNotIn('uid', $removeUserIdList)
  339. ->whereIn('status', [0, 1, 2, 3])
  340. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  341. ->whereBetween("pay_time", [$startTime, $endTime])
  342. ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单
  343. ->select();
  344. // 计算总业绩
  345. $totalPv = 0;
  346. foreach ($orders as $order) {
  347. switch ($order['total_price']) {
  348. case 1180:
  349. $totalPv += 700;
  350. break;
  351. case 11800:
  352. $totalPv += 7000;
  353. break;
  354. case 10620:
  355. $totalPv += 6300;
  356. break;
  357. case 2360:
  358. $totalPv += 1400;
  359. break;
  360. case 9440:
  361. $totalPv += 5600;
  362. break;
  363. }
  364. }
  365. return $totalPv;
  366. }
  367. public function getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList = [])
  368. {
  369. // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
  370. $redEnvelopeList = Db::name("user_sign_hongbao")
  371. ->whereNotIn('uid', $removeUserIdList)
  372. ->where('status', 1)
  373. ->whereBetween("settlement_time", [$startTime, $endTime])
  374. ->select()
  375. ->toArray();
  376. return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
  377. }
  378. }