| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <?php
- // +----------------------------------------------------------------------
- // | EasyAdmin
- // +----------------------------------------------------------------------
- // | PHP交流群: 763822524
- // +----------------------------------------------------------------------
- // | 开源协议 https://mit-license.org
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
- // +----------------------------------------------------------------------
- namespace app\common\model;
- use app\common\model\ShopGoodsSpecType as Spec;
- use app\common\model\TimeModel;
- use think\facade\Db;
- use think\Model;
- class JhGoodsModel extends Model
- {
- protected $name = "jh_goods";
- public function jhsellSubmit($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('个数只能是整数');
- }
- 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']);
- }
- }
|