| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\command\test\ln;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- class UserBill extends Command
- {
- protected function configure()
- {
- $this->setName('user_bill')->setDescription('用户收益处理');
- }
- protected function execute(Input $input, Output $output)
- {
- try {
- $zhitui_rate_setting = systemConfig('zhitui_rate');
- $zhitui_rate = $zhitui_rate_setting['zhitui_rate'] ?? 0;
- $zhitui_user_rate = $zhitui_rate_setting['zhitui_user_rate'] ?? 0;
- $chuangke_user_list = Db::name('user')->field('uid,user_group,phone,nickname')->where('user_group', 4)->select()->toArray();
- foreach ($chuangke_user_list as $chuangke_user) {
- $child_uids = Db::name('user')->where('spread_uid', $chuangke_user['uid'])->column('uid');
- if (!$child_uids)
- continue;
- $store_order_list = Db::name('store_order')->where('paid', 1)
- ->where('is_settlement', 1)
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn('uid', $child_uids)
- ->select()
- ->toArray();
- foreach ($store_order_list as $store_order) {
- $user_bill = Db::name('user_bill')
- ->where('commission_type', 3)
- ->where('link_id', $store_order['order_id'])
- ->where('order_sn', $store_order['order_sn'])
- ->find();
- if ($user_bill) {
- $create_time_md = date("m.d", strtotime("+1 days", strtotime($store_order['create_time'])));
- $new_title = "直推奖{$create_time_md}";
- Db::name('user_bill')
- ->where('bill_id', $user_bill['bill_id'])
- ->update([
- 'title' => $new_title,
- ]);
- echo "订单号{$store_order['order_sn']},收益表ID{$user_bill['bill_id']},原标题{$user_bill['title']}, 新标题{$new_title}\r\n";
- }
- // $nickname = Db::name('user')->where('uid', $store_order['uid'])->value('nickname');
- // $zhitui_rate1 = $store_order['total_price'] >= 19800 ? $zhitui_rate : $zhitui_user_rate;
- // $total_price = $store_order['total_price'] + $store_order['youhui_price'];
- // $zhitui_money = round($total_price* $zhitui_rate1 * 0.01, 1);
- //
- // $mark = $nickname.'购买商品';
- // $title = "直推奖".date('m.d');
- //
- // $user_bill = Db::name('user_bill')
- // ->where('commission_type', 3)
- // ->where('link_id', $store_order['order_id'])
- // ->where('order_sn', $store_order['order_sn'])
- // ->find();
- // if (empty($user_bill)) {
- // echo "step1,{$chuangke_user['phone']},{$mark},{$title},应获得佣金{$zhitui_money} 订单号{$store_order['order_sn']} 实际获得0\r\n";
- //
- // } else if ($zhitui_money != $user_bill['number']) {
- // echo "step2,{$chuangke_user['phone']},{$mark},{$title},应获得佣金{$zhitui_money} 订单号{$store_order['order_sn']} 实际获得{$user_bill['number']}\r\n";
- // $zhitui_money = $zhitui_money-$user_bill['number'];
- // }
- //
- // $commission_type = 3;
- // $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']);
- }
- }
- } catch (Exception $e) {
- var_dump($e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage());
- }
- }
- 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)
- {
- if ($number == 0) {
- return;
- }
- $currency = ($type == 'commission' ? 'brokerage_price' : 'score');
- $number = decimal2($number);
- $data = [
- 'link_id' => $order_id,//关联订单id
- "uid" => $uid,
- "pm" => 1,
- "title" => $title,
- "category" => "now_money",
- "type" => $type,//明细类型 commission佣金 integral积分
- "number" => $number,
- "mark" => $mark,
- "status" => $status,//0 = 待确定 1 = 有效 -1 = 无效
- "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创客补贴√',
- "order_sn" => $order_sn,//订单号
- "mer_id" => $mer_id,//商户id
- "source" => $source,//积分
- "month" => $month,//奖励月份
- "type_shop" => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
- 'create_time'=>$create_time
- ];
- if ($status == 1) {
- $data['take_time'] = time();
- //商户佣金类型处理
- if (in_array($commission_type, [7,12,19])) {
- $balance = Db::name('merchant')->where('mer_id', $mer_id)->value($currency);
- $data['balance'] = decimal2($balance);
- Db::name("merchant")->where("mer_id", $mer_id)->inc($currency, $number)->update();
- } else {
- $balance = Db::name('user')->where('uid', $uid)->value($currency);
- $data['balance'] = decimal2($balance);
- Db::name("user")->where("uid", $uid)->inc($currency, $number)->update();
- }
- Db::name('log')->insert(['data' => "{$title}佣金增加{$number}," . json_encode($data)]);
- }
- Db::name("user_bill")->insert($data);
- }
- }
|