$jh_max_money ){ sr_throw('不能高于最高价'); } // $new_count = intval($params['count']); if (!(is_numeric($params['count']) && intval($params['count'])==$params['count'])){ sr_throw('个数只能是整数'); } if (sr_getdianLen($params['price']) > 2){ sr_throw('价格最多两位小数'); } $model = new UserModel(); $userinfo = $model->getUserDetailByUid($uid); if ($userinfo['tz_num'] < $params['count']){ sr_throw('当前通证不足'); } edit_user_tz(8, $uid, $params['count']); self::insert([ 'uid'=>$uid, 'jh_count'=>$params['count'], 'price'=>$params['price'], 'total_price'=>$params['count'] * $params['price'], 'create_time'=>sr_getcurtime(time()), 'status'=>1 ]); } public function jhBuyGoodsSubmit($uid, $params){ if (intval($params['count']) <= 0 || floatval($params['price']) <= 0){ sr_throw('参数错误'); } $jh_min_money = sysconfig('jhconfig', 'jh_min_money'); $jh_max_money = sysconfig('jhconfig', 'jh_max_money'); if ($params['price'] < $jh_min_money ){ sr_throw('不能小于最低价'); } if ($params['price'] > $jh_max_money ){ sr_throw('不能高于最高价'); } // $new_count = intval($params['count']); if (!(is_numeric($params['count']) && intval($params['count'])==$params['count'])){ sr_throw('个数只能是整数'); } $model = new UserModel(); $userinfo = $model->getUserDetailByUid($uid); if (sr_getdianLen($params['price']) > 2){ sr_throw('价格最多两位小数'); } $total_money = $params['count'] * $params['price']; if ($userinfo['money'] < $total_money){ sr_throw('当前余额不足'); } edit_user_money(20, $uid, $total_money); self::insert([ 'uid'=>$uid, 'type'=>2, 'jh_count'=>$params['count'], 'price'=>$params['price'], 'total_price'=>$total_money, 'create_time'=>sr_getcurtime(time()), 'status'=>1 ]); } public function getSellList($uid, $para){ $order = 'id asc'; $page = $para['page']; $limit = $para['limit']; switch (intval($para['sort'])){ case 1: $order = 'g.total_price asc'; break; case 2: $order = 'g.total_price desc'; break; case 3: $order = 'g.price asc'; break; case 4: $order = 'g.price desc'; break; default: break; } $list = $this->alias('g') ->where('g.status', 1) ->where('g.type', 1) ->leftJoin('user u', 'u.id = g.uid') ->field('g.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') ->withAttr('avatar', function ($val, $data){ return getWebUrl().'/'.$val; }) ->withAttr('level', function ($val, $data){ return 0; }) ->order($order) ->page($page, $limit) ->select()->toArray(); return api_succ_return(['msg'=>'成功', 'data'=>$list]); } public function jhBuyList($uid, $para){ $order = 'id asc'; $page = $para['page']; $limit = $para['limit']; switch (intval($para['sort'])){ case 1: $order = 'g.total_price asc'; break; case 2: $order = 'g.total_price desc'; break; case 3: $order = 'g.price asc'; break; case 4: $order = 'g.price desc'; break; default: break; } $list = $this->alias('g') ->where('g.status', 1) ->where('g.type', 2) ->leftJoin('user u', 'u.id = g.uid') ->field('g.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') ->withAttr('avatar', function ($val, $data){ return getWebUrl().'/'.$val; }) ->withAttr('level', function ($val, $data){ return 0; }) ->order($order) ->page($page, $limit) ->select()->toArray(); return api_succ_return(['msg'=>'成功', 'data'=>$list]); } public function jhsellList($uid, $para){ $order = 'id desc'; $page = $para['page']; $limit = $para['limit']; $status = isset($para['status'])?$para['status']:0; // switch (intval($para['sort'])){ // case 1: // $order = 'g.total_price asc'; // break; // case 2: // $order = 'g.total_price desc'; // break; // case 3: // $order = 'g.price asc'; // break; // case 4: // $order = 'g.price desc'; // break; // default: // break; // // // } $arr_status = []; if ($status == 0|| empty($status)){ $arr_status = [1,2,3,4]; }else{ $arr_status = [$status]; } $list = $this->where('uid', $uid) ->where('status', 'in',$arr_status) ->where('type', 1) // ->leftJoin('user u', 'u.id = g.uid') // ->field('g.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') // ->withAttr('avatar', function ($val, $data){ // return getWebUrl().'/'.$val; // }) ->order($order) ->page($page, $limit) ->select()->toArray(); return $list; } public function jhMyBuyList($uid, $para){ $order = 'id desc'; $page = $para['page']; $limit = $para['limit']; $status = isset($para['status'])?$para['status']:0; // switch (intval($para['sort'])){ // case 1: // $order = 'g.total_price asc'; // break; // case 2: // $order = 'g.total_price desc'; // break; // case 3: // $order = 'g.price asc'; // break; // case 4: // $order = 'g.price desc'; // break; // default: // break; // // // } $arr_status = []; if ($status == 0|| empty($status)){ $arr_status = [1,2,3,4]; }else{ $arr_status = [$status]; } $list = $this->where('uid', $uid) ->where('status', 'in',$arr_status) ->where('type', 2) // ->leftJoin('user u', 'u.id = g.uid') // ->field('g.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') // ->withAttr('avatar', function ($val, $data){ // return getWebUrl().'/'.$val; // }) ->order($order) ->page($page, $limit) ->select()->toArray(); return $list; } public function jhUnSellGoods($uid, $para){ $goods_info = $this->where('id', $para['g_id'])->find(); $time = time(); if (!$goods_info){ sr_throw("参数错误"); } if ($goods_info['uid'] != $uid){ sr_throw('无权操作'); } if ($goods_info['status'] != 1){ sr_throw('状态错误'); } $goods_info->save([ 'status'=>2, 'unsell_time'=>sr_getcurtime($time) ]); edit_user_tz(10,$uid ,$goods_info['jh_count']); } public function jhUnBuyGoods($uid, $para){ $goods_info = $this->where('id', $para['g_id'])->find(); $time = time(); if (!$goods_info){ sr_throw("参数错误"); } if ($goods_info['uid'] != $uid){ sr_throw('无权操作'); } if ($goods_info['status'] != 1){ sr_throw('状态错误'); } $goods_info->save([ 'status'=>2, 'unsell_time'=>sr_getcurtime($time) ]); edit_user_money(21,$uid ,$goods_info['total_price']); } }