123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- namespace app\common\controller;
- use app\common\model\BondFinance;
- use app\common\model\Finance;
- use app\common\model\Mining;
- use app\common\model\Order;
- use app\common\model\OrderFrequency;
- use app\common\model\User;
- use app\common\model\VendibilityFinance;
- use app\web\model\Msg;
- class Orde
- {
-
-
- public static function push_order($user, $order_id, $push_user_id, $order, $count_order, $sxf_money = 0)
- {
-
- if ($count_order + 1 == 5) {
- $money = $user->money - $order->out_game;
- } else {
- $money = $user->money - $order->tong_money;
- }
- $push_money = $user->push_money - $order->number;
- User::update(["money" => $money, "push_money" => $push_money], ["id" => $push_user_id]);
- $where["id"] = $order_id;
- $update["push_user"] = $push_user_id;
- $update["sxf_money"] = $money;
- $update["status"] = 1;
- $update["stat_time"] = time() + 1 * 3600;
- Order::where($where)->update($update);
-
- self::Finance($push_user_id, "卖出BTS", $money, 1);
-
- $buy_user_id = $order->buy_user;
- $buy_user = User::where(["id" => $buy_user_id])->field("id,phone,mail")->find();
-
- $content = "其他对您卖出BTS,请登录前去查看";
- if ($buy_user->phone) {
- Msg::phone($content, $user->phone);
- } else {
- Msg::mail($content, $user->mail);
- }
- }
-
- public static function transfer($user_id, $puser_id, $money, $jmoney, $name)
- {
-
- User::update(["money" => $jmoney], ["id" => $user_id]);
-
- $where["id"] = $puser_id;
- $user = User::where($where)->field("money,name,phone,mail")->find();
- $zong_money = $user->money + $money;
- User::update(["money" => $zong_money], ["id" => $puser_id]);
- self::Finance($user_id, "您给用户" . $user->name . "转账", $money, 1);
- self::Finance($puser_id, "用户" . $name . "给您转账", $money, 0);
-
- $content = "用户" . $name . "给你转账" . $money . "BTS";
- if ($user->phone) {
- Msg::phone($content, $user->phone);
- } else {
- Msg::mail($content, $user->mail);
- }
- }
-
- public static function bond_transfer($user, $user_id, $money, $ensure_money, $type)
- {
- if ($type == 0) {
- $money = $user->money - $money;
- $ensure_moneys = $user->ensure_money + $ensure_money;
- User::update(["money" => $money, "ensure_money" => $ensure_moneys], ["id" => $user_id]);
-
- self::Finance($user_id, "保证金充值", $money, 1);
- self::bond_finance($user_id, "保证金充值", $money, 0);
- } else {
- $money = $user->money + $money;
- $ensure_moneys = $user->ensure_money - $ensure_money;
- User::update(["money" => $money, "ensure_money" => $ensure_moneys], ["id" => $user_id]);
-
- self::Finance($user_id, "保证金提现", $money, 0);
- self::bond_finance($user_id, "保证金提现", $money, 1);
- }
- }
- public static function admin_Recharge($user_id, $money)
- {
- $where["id"] = $user_id;
- $user = User::where($where)->field("money,name,phone,mail")->find();
- $zong_money = $user->money + $money;
- User::update(["money" => $zong_money], ["id" => $user_id]);
- self::Finance($user_id, "充值成功", $money, 0);
-
- $content = "充值" . $money . "BTS已处理";
- if ($user->phone) {
- Msg::phone($content, $user->phone);
- } else {
- Msg::mail($content, $user->mail);
- }
- }
-
- public static function order_fail($msg, $order)
- {
-
- $mining = Mining::where(["id" => $order->mining_id])->find();
-
- $ensure_money = $mining->breach_money;
- $where["id"] = $order->buy_user;
- $user = User::where($where)->find();
- $update["ensure_money"] = $user->ensure_money - $ensure_money;
-
- self::bond_finance($order->buy_user, "交易失败扣除保证金", $ensure_money, 1);
- User::update($update, $where);
-
- $push_user = User::where(["id" => $order->push_user])->find();
- $push_money = $push_user->push_money + $order->number;
-
- $add_money = $ensure_money + $order->sxf_money;
- $money = $push_user->money + $add_money;
- User::update(["money" => $money, "push_money" => $push_money], ["id" => $order->push_user]);
-
- self::Finance($order->push_user, "交易失败退回手续费", $order->sxf_money, 0);
- self::Finance($order->push_user, "交易失败获得违约金", $ensure_money, 0);
-
- $where_order["id"] = $order->id;
- $update_order["msg"] = $msg;
- $update_order["status"] = 5;
- $update_order["end_time"] = time();
- Order::update($update_order, $where_order);
- return 1;
- }
-
- public static function order_success($order)
- {
-
- $update_order["status"]=3;
- $update_order["end_time"]=time();
- Order::update($update_order,["id"=>$order->id]);
- $buy_user = $order->buy_user;
- $push_user = $order->push_user;
- $mining_id = $order->mining_id;
- $mining = Mining::where(["id" => $mining_id])->find();
- if (!$mining){
- json_result(400,"价格区已经不存在了,无法计算");
- }
-
-
- $buy_order_frequency = OrderFrequency::where(["user_id" => $buy_user, "mining_id" => $mining_id])->find();
- if (!$buy_order_frequency) {
- $buy_count = 1;
- $buy_number = 1;
- $push_number = 0;
- $add_buy["user_id"] = $buy_user;
- $add_buy["mining_id"] = $mining_id;
- $add_buy["buy"] = 1;
- $add_buy["push"] = 0;
- OrderFrequency::create($add_buy);
- } else {
- $buy_count = $buy_order_frequency->buy + 1;
- $buy_number = $buy_count;
- $push_number = $buy_order_frequency->push;
- OrderFrequency::update(["buy" => $buy_count], ["id" => $buy_order_frequency->id]);
- }
- $buy_user_data = User::where(["id" => $buy_user])->find();
- $keshou_money = $mining->enlarge_quota;
-
- if ($buy_count == 1) {
- $pool_money = $mining->mining;
- $update_buy["pool_money"] = $buy_user_data->pool_money + $pool_money;
- self::VendonolotyFinance($buy_user, $mining_id, $order->id, $order->number, $mining->mining, $keshou_money, $buy_number, $push_number, 1);
- }
- $enlarge_quota = $keshou_money + $buy_user_data->push_money;
-
- $update_buy["push_money"] = $enlarge_quota;
- User::update($update_buy, ["id" => $buy_user]);
-
- $push_order_frequency = OrderFrequency::where(["user_id" => $push_user, "mining_id" => $mining_id])->find();
- if (!$push_order_frequency) {
- $push_count = 1;
- $add_push["user_id"] = $push_user;
- $add_push["mining_id"] = $mining_id;
- $add_push["buy"] = 0;
- $add_push["push"] = 1;
- OrderFrequency::create($add_push);
- } else {
- $push_count = $push_order_frequency->push + 1;
- OrderFrequency::update(["push" => $push_count], ["id" => $push_order_frequency->id]);
- }
-
- $push_user_data = User::where(["id" => $push_user])->find();
- $kuangjine = $push_user_data->pool_money - $mining->num;
- User::update(["pool_money" => $kuangjine], ["id" => $push_user]);
- if ($push_count == 5) {
- $direct_push = $mining->direct_push;
- $second_push = $mining->second_push;
-
- if ($push_user_data->pid) {
- $zhitui_push_user = User::where(["id" => $push_user_data->pid])->find();
- if ($zhitui_push_user) {
-
- if ($direct_push) {
-
- $zhitui_time =strtotime($zhitui_push_user->update_time) + (24 * 3600);
- if ($zhitui_time >= time()) {
- $update_zhitui["money"] = $zhitui_push_user->money + $direct_push;
- User::update($update_zhitui, ["id" => $push_user_data->pid]);
-
- self::Finance($push_user_data->pid, "获得直推奖励", $direct_push, 0,1);
- }
- }
- if ($zhitui_push_user->pid) {
-
- if ($second_push) {
-
- $ciji_push_user = User::where(["id" => $zhitui_push_user->pid])->find();
- if ($ciji_push_user) {
- $ciji_time = (int)strtotime($ciji_push_user->update_time) + 24 * 3600;
- if ($ciji_time >= time()) {
- $update_ciji["money"] = $ciji_push_user->money - $second_push;
- User::update($update_ciji, ["id" => $zhitui_push_user->pid]);
-
- self::Finance($zhitui_push_user->pid, "获得次推奖励", $second_push, 0,1);
- }
- }
- }
- }
- }
- }
- }
- }
-
- public static function Finance($user_id, $name, $money, $status,$daili=0)
- {
- $add["user_id"] = $user_id;
- $add["name"] = $name;
- $add["money"] = $money;
- $add["status"] = $status;
- $add["daili"] = $daili;
- $add["add_time"] = time();
- Finance::create($add);
- }
-
- public static function bond_finance($user_id, $name, $money, $status)
- {
- $add["user_id"] = $user_id;
- $add["name"] = $name;
- $add["money"] = $money;
- $add["status"] = $status;
- $add["add_time"] = time();
- BondFinance::create($add);
- }
-
- public static function VendonolotyFinance($user_id, $mining_id, $order_id, $money, $pool, $push_money, $buy, $push, $status)
- {
- $add["user_id"] = $user_id;
- $add["mining_id"] = $mining_id;
- $add["order_id"] = $order_id;
- $add["money"] = $money;
- $add["pool"] = $pool;
- $add["push_money"] = $push_money;
- $add["buy"] = $buy;
- $add["push"] = $push;
- $add["status"] = $status;
- $add["add_time"] = time();
- VendibilityFinance::create($add);
- }
- }
|