| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\common\logic;
- use Exception;
- use think\Env;
- use think\Error;
- use think\Loader ;
- use app\common\model\UserPledge;
- use app\common\model\ProductPledges;
- class PledgeLogic
- {
-
- //获取产品信息 user_pledge
- public static function getByProductIdList(object $list, string $lan = 'zh')
- {
- $model = Loader::model('ProductLists');
- foreach ($list as &$item) {
- $item['product_list'] = $model->whereIn('id', $item->product_id)->column('id,thum,'.$lan.'_name as name');
- }
- return $list;
- }
- /*
- * 获取产品信息
- */
- public static function getHoldProductList($user_id, $product_id)
- {
- $model = Loader::model('ProductOrder');
- return $model::where('user_id', $user_id)->where('product_id', $product_id)->where('status', $model::Paid)->field('id,order_no')->select();
-
- }
- //添加质抵押订单
- public static function setPledgeOrder(object $pledge, array $order_no, int $user_id)
- {
- $model = Loader::model('ProductOrder');
- $order = $model::where('user_id', $user_id)->whereIn('order_no', $order_no)->select();
- if(empty($order) || count($order) != count($order_no)) throw new Exception('订单不存在');
- $pledge_num = 1;
- if($pledge->type_id == ProductPledges::Single){
- $pledge_num = count($order);
- }
-
- //添加订单
- Loader::model('UserPledge')::setPledgeData($user_id, $pledge->id, $pledge->product_id, $pledge->day_num, $pledge_num);
-
- //修改状态
- return $model->whereIn('order_no', $order_no)->setField('status', $model::Freeze);
- }
- //获取质抵押订单列表
- //(60*60*24)*(当前时间-最后一次收取时间)
- public static function getPledgeOrderList(int $user_id)
- {
- $model = Loader::model('UserPledge');
- $list = $model::where('user_id', $user_id)->where('status', $model::Ongoing)->select();
- if(empty($list)) throw new Exception('暂无质押订单');
- $day = 86400;
- $total = 0; //当前累计收益
- $growth= 0; //增长累计收益
- $time = time();
- foreach ($list as $item) {
- $reta = bcdiv($item->day_num, $day, 2); //天数
- $inter = ($item->last_time == 0) ? $time - $item->create_time: $time - $item->last_time; //最后收取时间
- $total += bcmul($reta, $inter, 2) * $item->num; //累计收益
- $growth += $reta* $item->num;
- }
- return ['total' => $total, 'growth' => $growth, 'list' => $list];
- }
- }
|