where('id', $id)->find(); $userinfo = Db::name('user')->where('id', $uid)->find(); if (!$ginfo){ sr_throw("参数错误"); } if ($ginfo['buy_count'] < 1){ sr_throw('已经被人购买了'); } try { $ginfo->where('id', $id)->dec('buy_count', 1)->update(); }catch (Exception $e){ sr_throw('购买失败,请刷新列表'); } if ($ginfo['uid'] == $uid){ sr_throw('不能购买自己的卖单'); } if ($userinfo['money'] < $ginfo['total_price']){ sr_throw('余额不足'); } // 判断用户的余额 // $ginfo->save([ // 'status'=>3 // ]); $time = time(); $order_sn = creatJhOrderSn($uid); if (!Db::name('tz_log')->where('uid2', $order_sn)->where('type', 2)->find()){ edit_user_tz(2, $uid, $ginfo['jh_count'], $uid, $order_sn); } edit_user_money(14, $uid, $ginfo['total_price'], 0, 0, $ginfo['id']); edit_user_money(19, $ginfo['uid'], $ginfo['total_price'], 0, 0, $ginfo['id']); $this->insertGetId([ 'jh_ordersn'=>$order_sn, 'seller_uid'=>$ginfo['uid'], 'buyer_uid'=>$uid, 'b_endtime'=>sr_getcurtime($time+env('JHCONF.BUYER_UPLOAD_IMG')), 'create_time'=>sr_getcurtime($time), 'jh_count'=>$ginfo['jh_count'], 'price'=>$ginfo['price'], 'total_price'=>$ginfo['total_price'], 'g_id'=>$ginfo['id'], 'status'=>4 ]); $ginfo->save([ 'status'=>4 ]); // sr_throw(); // $order_info->save([ // 'status'=>4, // 's_time'=>sr_getcurtime($time) // ]); // Db::name('jh_goods')->where('id', $order_info['g_id'])->save([ // 'status'=>4 // ]); } public function jhSellSubmitDown($uid, $id){ $model = new JhGoodsModel(); $ginfo = $model->where('id', $id)->find(); $userinfo = Db::name('user')->where('id', $uid)->find(); if (!$ginfo){ sr_throw("参数错误"); } if ($ginfo['buy_count'] < 1){ sr_throw('已经被人卖出去了'); } try { $ginfo->where('id', $id)->dec('buy_count', 1)->update(); }catch (Exception $e){ sr_throw('购买失败,请刷新列表'); } if ($ginfo['uid'] == $uid){ sr_throw('不能处理自己的买单'); } if ($userinfo['tz_num'] < $ginfo['jh_count']){ sr_throw('通证不足'); } // 判断用户的余额 // $ginfo->save([ // 'status'=>3 // ]); $time = time(); $order_sn = creatJhOrderSn($uid); // if (!Db::name('tz_log')->where('uid2', $order_sn)->where('type', 2)->find()){ // // } edit_user_tz(11, $uid, $ginfo['jh_count'], $uid, $order_sn); edit_user_tz(12, $ginfo['uid'], $ginfo['jh_count'], $uid, $order_sn); edit_user_money(22, $uid, $ginfo['total_price'], 0, 0, $ginfo['id']); // edit_user_money(19, $ginfo['uid'], $ginfo['total_price'], 0, 0, $ginfo['id']); $this->insertGetId([ 'jh_ordersn'=>$order_sn, 'seller_uid'=>$uid, 'buyer_uid'=>$ginfo['uid'], 'b_endtime'=>sr_getcurtime($time+env('JHCONF.BUYER_UPLOAD_IMG')), 'create_time'=>sr_getcurtime($time), 'jh_count'=>$ginfo['jh_count'], 'price'=>$ginfo['price'], 'total_price'=>$ginfo['total_price'], 'g_id'=>$ginfo['id'], 'status'=>4, 'type'=>2 ]); $ginfo->save([ 'status'=>4 ]); // sr_throw(); // $order_info->save([ // 'status'=>4, // 's_time'=>sr_getcurtime($time) // ]); // Db::name('jh_goods')->where('id', $order_info['g_id'])->save([ // 'status'=>4 // ]); } public function jhOrderPayWay($uid, $jh_orderid){ $orderinfo = Db::name('jh_order')->where('jh_ordersn', $jh_orderid)->find(); if (!$orderinfo){ sr_throw('参数错误'); } if ($orderinfo['buyer_uid'] != $uid){ sr_throw('无权查看,不是你的买单'); } return $pay_info = getUserPayWay($orderinfo['seller_uid']); } public function jhOrderList($uid, $roles, $page, $limit){ if (!in_array($roles, ['seller', 'buyer'])){ sr_throw('参数错误'); } if ($roles == 'seller'){ $where = array(); $where[] = ['o.seller_uid', '=', $uid]; $where[] = ['o.type', '=', 1]; $list = $this->alias('o') ->leftJoin('user u', 'u.id = o.buyer_uid') ->where($where) ->field('o.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') ->withAttr('avatar', function ($val, $data){ return getWebUrl().'/'.$val; }) ->order('o.create_time desc') ->page($page, $limit) ->select()->toArray(); return $list; } if ($roles == 'buyer'){ $where = array(); $where[] = ['o.buyer_uid', '=', $uid]; $where[] = ['o.type', '=', 1]; $list = $this->alias('o') ->leftJoin('user u', 'u.id = o.seller_uid') ->where($where) ->field('o.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') ->withAttr('avatar', function ($val, $data){ return getWebUrl().'/'.$val; }) ->order('o.create_time desc') ->page($page, $limit) ->select()->toArray(); return $list; } } public function jhBuyOrderList($uid, $roles, $page, $limit){ if (!in_array($roles, ['seller', 'buyer'])){ sr_throw('参数错误'); } if ($roles == 'seller'){ $where = array(); $where[] = ['o.seller_uid', '=', $uid]; $where[] = ['o.type', '=', 2]; $list = $this->alias('o') ->leftJoin('user u', 'u.id = o.buyer_uid') ->where($where) ->field('o.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') ->withAttr('avatar', function ($val, $data){ return getWebUrl().'/'.$val; }) ->order('o.create_time desc') ->page($page, $limit) ->select()->toArray(); return $list; } if ($roles == 'buyer'){ $where = array(); $where[] = ['o.buyer_uid', '=', $uid]; $where[] = ['o.type', '=', 2]; $list = $this->alias('o') ->leftJoin('user u', 'u.id = o.seller_uid') ->where($where) ->field('o.*,u.nickname,u.mobile,u.avatar,u.level,u.credit') ->withAttr('avatar', function ($val, $data){ return getWebUrl().'/'.$val; }) ->order('o.create_time desc') ->page($page, $limit) ->select()->toArray(); return $list; } } public function jhOrderSurePay($uid, $para){ $time = time(); $orderid = $para['jh_orderid']; if (empty($para['img']) || empty($para['pay_way']) || empty($orderid)){ sr_throw('参数错误'); } $order_info = $this->where('jh_ordersn', $orderid)->find(); if ($order_info['status'] != 1){ sr_throw('状态错误'); } if (!$order_info){ sr_throw("参数错误"); } if ($order_info['buyer_uid'] != $uid){ sr_throw('无权操作'); } if ($order_info['b_endtime'] < sr_getcurtime($time)){ sr_throw('已超时'); } $order_info->save([ 'status'=>2, 's_endtime'=>sr_getcurtime($time+env('JHCONF.SERLL_SURE_TIME')), 'b_time'=>sr_getcurtime($time), 'buyer_payway'=>$para['pay_way'], 'buyer_payimg'=>$para['img'] ]); } public function jhOrderSellerSureDown($uid, $para){ $time = time(); $orderid = $para['jh_orderid']; if (empty($orderid)){ sr_throw('参数错误'); } $order_info = $this->where('jh_ordersn', $orderid)->find(); if ($order_info['status'] != 2){ sr_throw('状态错误'); } if (!$order_info){ sr_throw("参数错误"); } if ($order_info['seller_uid'] != $uid){ sr_throw('无权操作'); } if ($order_info['s_endtime'] < sr_getcurtime($time)){ sr_throw('已超时'); } $order_info->save([ 'status'=>4, 's_time'=>sr_getcurtime($time) ]); if (!Db::name('tz_log')->where('uid2', $order_info['jh_ordersn'])->where('type', 2)->find()){ edit_user_tz(2, $order_info['buyer_uid'], $order_info['jh_count'], $uid, $order_info['jh_ordersn']); } Db::name('jh_goods')->where('id', $order_info['g_id'])->save([ 'status'=>4 ]); } public function jhBuyerDiverOrder($uid, $para){ $time = time(); $order_id = $para['jh_orderid']; if (empty($para['diver_reason'])){ sr_throw('参数错误'); } $order_info = $this->where('jh_ordersn', $order_id)->find(); if (!$order_info){ sr_throw('参数错误'); } if ($order_info['buyer_uid']!= $uid){ sr_throw('无权操作'); } if (!in_array($order_info['status'], [1,2])){ if ($order_info['status'] == 3){ sr_throw('订单正在申诉中,请耐心等待系统处理'); } if ($order_info['status'] == 4){ sr_throw('订单已经完成或申诉已处理完成'); } } $order_info->save([ 'status'=>3, 'diver_type'=>2, 'diver_reason'=>$para['diver_reason'], 'diver_desc'=>$para['diver_desc'], 'diver_time'=>sr_getcurtime($time) ]); } public function jhSellerDiverOrder($uid, $para){ $time = time(); $order_id = $para['jh_orderid']; if (empty($para['diver_reason'])){ sr_throw('参数错误'); } $order_info = $this->where('jh_ordersn', $order_id)->find(); if (!$order_info){ sr_throw('参数错误'); } if ($order_info['seller_uid']!= $uid){ sr_throw('无权操作'); } if (!in_array($order_info['status'], [1,2])){ if ($order_info['status'] == 3){ sr_throw('订单正在申诉中,请耐心等待系统处理'); } if ($order_info['status'] == 4){ sr_throw('订单已经完成或申诉已处理完成'); } } $order_info->save([ 'status'=>3, 'diver_type'=>1, 'diver_reason'=>$para['diver_reason'], 'diver_desc'=>$para['diver_desc'], 'diver_time'=>sr_getcurtime($time) ]); } }