UserBill.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\command\test\ln;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\facade\Db;
  7. class UserBill extends Command
  8. {
  9. protected function configure()
  10. {
  11. $this->setName('user_bill')->setDescription('用户收益处理');
  12. }
  13. protected function execute(Input $input, Output $output)
  14. {
  15. try {
  16. $zhitui_rate_setting = systemConfig('zhitui_rate');
  17. $zhitui_rate = $zhitui_rate_setting['zhitui_rate'] ?? 0;
  18. $zhitui_user_rate = $zhitui_rate_setting['zhitui_user_rate'] ?? 0;
  19. $chuangke_user_list = Db::name('user')->field('uid,user_group,phone,nickname')->where('user_group', 4)->select()->toArray();
  20. foreach ($chuangke_user_list as $chuangke_user) {
  21. $child_uids = Db::name('user')->where('spread_uid', $chuangke_user['uid'])->column('uid');
  22. if (!$child_uids)
  23. continue;
  24. $store_order_list = Db::name('store_order')->where('paid', 1)
  25. ->where('is_settlement', 1)
  26. ->whereIn('status', [0, 1, 2, 3])
  27. ->whereIn('uid', $child_uids)
  28. ->select()
  29. ->toArray();
  30. foreach ($store_order_list as $store_order) {
  31. $user_bill = Db::name('user_bill')
  32. ->where('commission_type', 3)
  33. ->where('link_id', $store_order['order_id'])
  34. ->where('order_sn', $store_order['order_sn'])
  35. ->find();
  36. if ($user_bill) {
  37. $create_time_md = date("m.d", strtotime("+1 days", strtotime($store_order['create_time'])));
  38. $new_title = "直推奖{$create_time_md}";
  39. Db::name('user_bill')
  40. ->where('bill_id', $user_bill['bill_id'])
  41. ->update([
  42. 'title' => $new_title,
  43. ]);
  44. echo "订单号{$store_order['order_sn']},收益表ID{$user_bill['bill_id']},原标题{$user_bill['title']}, 新标题{$new_title}\r\n";
  45. }
  46. // $nickname = Db::name('user')->where('uid', $store_order['uid'])->value('nickname');
  47. // $zhitui_rate1 = $store_order['total_price'] >= 19800 ? $zhitui_rate : $zhitui_user_rate;
  48. // $total_price = $store_order['total_price'] + $store_order['youhui_price'];
  49. // $zhitui_money = round($total_price* $zhitui_rate1 * 0.01, 1);
  50. //
  51. // $mark = $nickname.'购买商品';
  52. // $title = "直推奖".date('m.d');
  53. //
  54. // $user_bill = Db::name('user_bill')
  55. // ->where('commission_type', 3)
  56. // ->where('link_id', $store_order['order_id'])
  57. // ->where('order_sn', $store_order['order_sn'])
  58. // ->find();
  59. // if (empty($user_bill)) {
  60. // echo "step1,{$chuangke_user['phone']},{$mark},{$title},应获得佣金{$zhitui_money} 订单号{$store_order['order_sn']} 实际获得0\r\n";
  61. //
  62. // } else if ($zhitui_money != $user_bill['number']) {
  63. // echo "step2,{$chuangke_user['phone']},{$mark},{$title},应获得佣金{$zhitui_money} 订单号{$store_order['order_sn']} 实际获得{$user_bill['number']}\r\n";
  64. // $zhitui_money = $zhitui_money-$user_bill['number'];
  65. // }
  66. //
  67. // $commission_type = 3;
  68. // $this->add_bill_gongfu($title, $zhitui_money, $chuangke_user['uid'], $mark, $commission_type, $store_order['order_sn'], $store_order['order_id'], $store_order['mer_id'], 0, 1,$store_order['pay_time']);
  69. }
  70. }
  71. } catch (Exception $e) {
  72. var_dump($e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage());
  73. }
  74. }
  75. public function add_bill_gongfu($title, $number, $uid, $mark, $commission_type, $order_sn, $order_id = 0, $mer_id = 0, $source = 0, $status = 0, $create_time = 0, $type = 'commission', $month = '', $is_mer = false)
  76. {
  77. if ($number == 0) {
  78. return;
  79. }
  80. $currency = ($type == 'commission' ? 'brokerage_price' : 'score');
  81. $number = decimal2($number);
  82. $data = [
  83. 'link_id' => $order_id,//关联订单id
  84. "uid" => $uid,
  85. "pm" => 1,
  86. "title" => $title,
  87. "category" => "now_money",
  88. "type" => $type,//明细类型 commission佣金 integral积分
  89. "number" => $number,
  90. "mark" => $mark,
  91. "status" => $status,//0 = 待确定 1 = 有效 -1 = 无效
  92. "commission_type" => $commission_type,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费 7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金 14-推荐代理收益√ 15邀请小区团长升级√ 16大V经理分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√',
  93. "order_sn" => $order_sn,//订单号
  94. "mer_id" => $mer_id,//商户id
  95. "source" => $source,//积分
  96. "month" => $month,//奖励月份
  97. "type_shop" => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
  98. 'create_time'=>$create_time
  99. ];
  100. if ($status == 1) {
  101. $data['take_time'] = time();
  102. //商户佣金类型处理
  103. if (in_array($commission_type, [7,12,19])) {
  104. $balance = Db::name('merchant')->where('mer_id', $mer_id)->value($currency);
  105. $data['balance'] = decimal2($balance);
  106. Db::name("merchant")->where("mer_id", $mer_id)->inc($currency, $number)->update();
  107. } else {
  108. $balance = Db::name('user')->where('uid', $uid)->value($currency);
  109. $data['balance'] = decimal2($balance);
  110. Db::name("user")->where("uid", $uid)->inc($currency, $number)->update();
  111. }
  112. Db::name('log')->insert(['data' => "{$title}佣金增加{$number}," . json_encode($data)]);
  113. }
  114. Db::name("user_bill")->insert($data);
  115. }
  116. }