| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- <?php
- // +----------------------------------------------------------------------
- // | EasyAdmin
- // +----------------------------------------------------------------------
- // | PHP交流群: 763822524
- // +----------------------------------------------------------------------
- // | 开源协议 https://mit-license.org
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
- // +----------------------------------------------------------------------
- namespace app\common\model;
- use think\facade\Db;
- use think\Model;
- class JhOrderModel extends Model
- {
- protected $name = "jh_order";
- public function jhBuySubmit($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['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)
- ]);
- }
- }
|