Example #1
0
 public function submit()
 {
     if (IS_POST && IS_AJAX) {
         $address_id = I('address_id', 0, 'intval');
         $pay_mode = I('pay_mode', 0, 'intval');
         $content = I('content', '', 'trim');
         if (empty($address_id)) {
             $this->error('收货地址不能为空');
         }
         if (empty($pay_mode)) {
             $this->error('支付方式不能为空');
         }
         $info = D('Flow')->get();
         if (empty($info['cart']) || empty($info['count_price']) || empty($info['count_num'])) {
             $this->error('购物车空空如也', U('Index/index'));
         }
         $info['content'] = $content;
         $order = array('order_id' => create_order_id('FX'), 'user_id' => $this->user_info['user_id'], 'address_id' => $address_id, 'price' => $info['count_price'], 'order_info' => serialize($info), 'create_time' => time(), 'update_time' => time(), 'pay_status' => 0, 'status' => 1);
         switch ($pay_mode) {
             case '1':
                 //微信支付
                 if (M('FxOrder')->add($order)) {
                     $this->success('成功', U('WxJsApi/index', array('order_id' => $order['order_id'])));
                 } else {
                     $this->error('系统错误');
                 }
                 break;
             case '2':
                 //余额支付
                 if ($this->user_info['fx_money'] >= $info['count_price']) {
                     $order['pay_status'] = 1;
                     $order['status'] = 2;
                     if (M('FxOrder')->add($order)) {
                         D('User')->pay($order['order_id']);
                         D('Flow')->clear();
                         $this->success('成功', U('User/index'));
                     } else {
                         $this->error('系统错误');
                     }
                 } else {
                     $this->error('余额不足');
                 }
                 break;
             default:
                 $this->error('支付方式不能为空');
                 break;
         }
     } else {
         $info = D('Flow')->get();
         if (empty($info['cart']) || empty($info['count_price']) || empty($info['count_num'])) {
             $this->error('购物车空空如也', U('Index/index'));
         }
         $this->assign('count_num', $info['count_num']);
         $this->assign('count_price', $info['count_price']);
         $consign_lists = D('UserConsign')->getList($this->user_info['user_id']);
         $this->assign('consign_lists', $consign_lists);
         $this->display();
     }
 }
Example #2
0
 public function add($productId, $price)
 {
     if (!$this->user_info['is_subscribe']) {
         $this->resultError('请先关注公众平台【' . C('WEB_SITE_TITLE') . '】', '', 'http://mp.weixin.qq.com/s?__biz=MzI2OTA4MzI4NA==&mid=401275684&idx=4&sn=215571f800f39c82095f7dca83728a0e#rd');
     }
     if (!$this->user_info['mobile']) {
         $this->resultError('请先完善个人资料手机号参数必填', '', U('Setting/index'));
     }
     $product_info = M('Product')->find($productId);
     // 拍品是否存在
     if (!$product_info) {
         $this->resultError('拍品不存在...');
     }
     if ($product_info['user_id'] == $this->user_info['user_id']) {
         $this->resultError('不可以自娱自乐...');
     }
     // 判断类型
     switch ($product_info['product_type']) {
         case '1':
             //加价
         //加价
         case '2':
             //竞速
             // 是否在拍卖
             if ($product_info['begin_time'] > NOW_TIME) {
                 $this->resultError('拍卖未开始');
             }
             if (NOW_TIME > $product_info['end_time']) {
                 $this->resultError('拍卖已结束');
             }
             // 拍品不在可出价状态
             if ($product_info['status'] != 1) {
                 $this->resultError('拍品不在可出价状态');
             }
             // 检查当前用户是否出价最高
             if (check_user_bid($productId, $this->user_info['user_id'])) {
                 $this->resultError('出价已经最高');
             }
             // 最低出价
             // $bid_price = max_bid_price($productId);
             $product_info['bid_info'] = M('ProductBid')->where(array('product_id' => $product_info['product_id']))->order('bid_price desc')->find();
             if ($product_info['bid_info']) {
                 $xz_bid = $product_info['bid_info']['bid_price'] + $product_info['range_price'];
             } else {
                 $xz_bid = $product_info['start_price'];
             }
             if ($xz_bid > $price) {
                 $this->resultError('最低加价' . $xz_bid);
             }
             // 出价
             $data = array('product_id' => $product_info['product_id'], 'user_id' => $this->user_info['user_id'], 'bid_price' => $price, 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'status' => 1);
             $result = M('ProductBid')->add($data);
             if (!$result) {
                 $this->resultError();
             }
             if ($product_info['reserve_price'] && $price >= $product_info['reserve_price']) {
                 // 下单
                 $order_id = create_order_id();
                 $end_time = strtotime('+2 day');
                 $data = array('order_id' => $order_id, 'shop_id' => $product_info['user_id'], 'user_id' => $this->user_info['user_id'], 'product_id' => $product_info['product_id'], 'price' => $price, 'postage' => $product_info['postage'], 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'end_time' => $end_time, 'status' => 1);
                 M('Order')->add($data);
                 $Product->where(array('product_id' => $product_info['product_id']))->setField('status', 2);
                 // 给卖家发
                 $data = array('first' => '你好,【' . $product_info['product_name'] . '】已经结拍,订单已经生成。', 'order_id' => $order_id, 'order_status' => '待支付(等待买家支付)', 'product_name' => $product_info['product_name'], 'order_price' => $price + $product_info['postage'], 'end_time' => '违约有效期:' . date('Y-m-d H:i:s', $end_time));
                 $this->sendOrder(get_shop_info($product_info['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data);
                 // 给买家发
                 $data['first'] = '你好,【' . $product_info['product_name'] . '】已经结拍,订单已经生成,请在付款有效期内付款。';
                 $this->sendOrder($this->user_info['openid'], U('Order/index', array('order_id' => $order_id)), $data);
                 // 通知买家
                 if ($product_info['bid_info']) {
                     $data = array('first' => '您的出价已被超越,【' . $this->user_info['user_name'] . '】出价' . $price . '元,已经得拍', 'product_id' => $product_info['product_id'], 'product_name' => $product_info['product_name'], 'remark' => '结拍时间:' . date('Y年m月d日 H:i:s', $product_info['end_time']));
                     $this->sendBid(get_shop_info($product_info['bid_info']['user_id'], 'openid'), U('Index/product', array('id' => $product_info['product_id'])), $data);
                 }
                 $this->resultSuccess('出价得拍');
             } else {
                 // 如果在结拍30内出价会延时5,3,1分
                 if ($product_info['end_time'] - NOW_TIME < 30) {
                     $product_ys_num = F('product_' . $product_info['product_id']);
                     switch ($product_ys_num) {
                         case '1':
                             $product_info['end_time'] += 180;
                             F('product_' . $product_info['product_id'], 2);
                             M('Product')->where(array('product_id' => $product_info['product_id']))->setField('end_time', $product_info['end_time']);
                             break;
                         case '2':
                             $product_info['end_time'] += 60;
                             F('product_' . $product_info['product_id'], 3);
                             M('Product')->where(array('product_id' => $product_info['product_id']))->setField('end_time', $product_info['end_time']);
                             break;
                         case '3':
                             // TODO:
                             break;
                         default:
                             $product_info['end_time'] += 300;
                             F('product_' . $product_info['product_id'], 1);
                             M('Product')->where(array('product_id' => $product_info['product_id']))->setField('end_time', $product_info['end_time']);
                             break;
                     }
                 }
                 // 通知买家
                 if ($product_info['bid_info']) {
                     $data = array('first' => '您的出价已被超越,【' . $this->user_info['user_name'] . '】出价' . $price . '元,目前领先', 'product_id' => $product_info['product_id'], 'product_name' => $product_info['product_name'], 'remark' => '提醒:' . date('Y年m月d日 H:i:s', $product_info['end_time']) . '拍卖结束');
                     $this->sendBid(get_shop_info($product_info['bid_info']['user_id'], 'openid'), U('Index/product', array('id' => $product_info['product_id'])), $data);
                 }
                 // 通知店铺
                 $data = array('first' => '您的拍品,【' . $this->user_info['user_name'] . '】出价' . $price . '元,目前领先', 'product_id' => $product_info['product_id'], 'product_name' => $product_info['product_name'], 'remark' => '提醒:' . date('Y年m月d日 H:i:s', $product_info['end_time']) . '拍卖结束');
                 $this->sendBid(get_shop_info($product_info['user_id'], 'openid'), U('Index/product', array('id' => $product_info['product_id'])), $data);
                 $this->resultSuccess();
             }
             break;
         case '3':
             //秒杀
             // 是否在拍卖
             if ($product_info['begin_time'] > NOW_TIME) {
                 $this->resultError('秒杀未开始');
             }
             if (NOW_TIME > $product_info['end_time']) {
                 $this->resultError('秒杀已结束');
             }
             // 拍品不在可出价状态
             if ($product_info['status'] != 1) {
                 $this->resultError('拍品不在可出价状态');
             }
             // 检查当前用户是否已经秒杀
             $map = array('product_id' => $product_info['product_id'], 'user_id' => $this->user_info['user_id']);
             $is_miaosha = M('ProductBid')->where($map)->find();
             if ($is_miaosha) {
                 $this->resultError('已经秒杀过了');
             }
             // 拍品数量
             if ($product_info['reserve_price'] < 1) {
                 $this->resultError('秒杀数量有限下次早点来哦');
             }
             // 秒杀价
             if ($price < $product_info['range_price']) {
                 $this->resultError('最低秒杀价' . $product_info['range_price']);
             }
             $map = array('product_id' => $product_info['product_id']);
             $result = M('Product')->where($map)->setDec('reserve_price', 1);
             if (!$result) {
                 $this->resultError();
             }
             $data = array('product_id' => $product_info['product_id'], 'user_id' => $this->user_info['user_id'], 'bid_price' => $price, 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'status' => 1);
             $result = M('ProductBid')->add($data);
             if (!$result) {
                 $this->resultError();
             }
             // 下单
             $order_id = create_order_id();
             $end_time = strtotime('+2 day');
             $data = array('order_id' => $order_id, 'shop_id' => $product_info['user_id'], 'user_id' => $this->user_info['user_id'], 'product_id' => $product_info['product_id'], 'price' => $price, 'postage' => $product_info['postage'], 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'end_time' => $end_time, 'status' => 1);
             M('Order')->add($data);
             // 最后一个结束拍卖
             if ($product_info['reserve_price'] == 1) {
                 M('Product')->where(array('product_id' => $product_info['product_id']))->setField('status', 2);
             }
             // 给卖家发
             $data = array('first' => '你好,【' . $product_info['product_name'] . '】秒杀拍品,有人秒杀抢购。', 'order_id' => $order_id, 'order_status' => '待支付(等待买家支付)', 'product_name' => $product_info['product_name'], 'order_price' => $price + $product_info['postage'], 'end_time' => '违约有效期:' . date('Y-m-d H:i:s', $end_time));
             $this->sendOrder(get_shop_info($product_info['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data);
             // 给买家发
             $data['first'] = '你好,【' . $product_info['product_name'] . '】订单已经生成,请在付款有效期内付款。';
             $this->sendOrder($this->user_info['openid'], U('Order/index', array('order_id' => $order_id)), $data);
             $this->resultSuccess();
             break;
         default:
             $this->resultError('参数错误...');
             break;
     }
 }
 private function _run()
 {
     G('begin');
     if (file_exists(WEB_ROOT . '/cron-0')) {
         return;
     } else {
         file_put_contents(WEB_ROOT . '/cron-0', 'cron-0');
     }
     /* 订单处理 */
     $Order = M('Order');
     $map = array('end_time' => array('elt', NOW_TIME), 'status' => array('in', '1,2,3'));
     $order_lsits = $Order->where($map)->select();
     foreach ($order_lsits as $key => $val) {
         $price = $val['price'] + $val['postage'];
         $product_name = get_product_info($val['product_id']);
         switch ($val['status']) {
             case '1':
                 //未付款
                 $parm = array('status' => 5, 'update_time' => $val['end_time'], 'desc' => '买家违约');
                 $data = array('first' => '你好,【' . $product_name . '】订单已经关闭,买家没有付款。', 'order_id' => $val['order_id'], 'order_status' => '已关闭(买家违约)', 'product_name' => $product_name, 'order_price' => $val['price'] + $val['postage'], 'end_time' => '违约时间:' . date('Y-m-d H:i:s', $val['end_time']));
                 break;
             case '2':
                 //未发货
                 $parm = array('status' => 5, 'update_time' => $val['end_time'], 'desc' => '卖家违约');
                 $data = array('first' => '你好,【' . $product_name . '】订单已经关闭,卖家没有发货,买家支付款将退还给买家', 'order_id' => $val['order_id'], 'order_status' => '已关闭(卖家违约)', 'product_name' => $product_name, 'order_price' => $price, 'end_time' => '违约时间:' . date('Y-m-d H:i:s', $val['end_time']));
                 // 退还买家支付款
                 fund_inc($val['user_id'], $price, '支付款退还');
                 break;
             case '3':
                 //系统自动签收
                 $parm = array('status' => 4, 'update_time' => $val['end_time'], 'desc' => '自动签收');
                 $data = array('first' => '你好,【' . $product_name . '】订单已经完成,系统自动签收。', 'order_id' => $val['order_id'], 'order_status' => '已完成(自动签收)', 'product_name' => $product_name, 'order_price' => $price, 'end_time' => '完成时间:' . date('Y-m-d H:i:s', $val['end_time']));
                 // 为商家充值
                 fund_inc($val['shop_id'], $price, '买卖交易');
                 break;
             default:
                 break;
         }
         // 更新订单状态
         $Order->where(array('order_id' => $val['order_id']))->save($parm);
         // 给卖家发
         $this->sendOrder(get_shop_info($val['shop_id'], 'openid'), U('Order/index', array('order_id' => $val['order_id'])), $data);
         // 给买家发
         $this->sendOrder(get_shop_info($val['user_id'], 'openid'), U('Order/index', array('order_id' => $val['order_id'])), $data);
     }
     /* 产品处理 */
     $Product = M('Product');
     $ProductBid = M('ProductBid');
     $map = array('status' => 1, 'end_time' => array('elt', NOW_TIME));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $key => $val) {
         switch ($val['product_type']) {
             case '1':
                 //普通
             //普通
             case '2':
                 //竞速
                 $bid_info = $ProductBid->where(array('product_id' => $val['product_id']))->order('bid_price desc')->find();
                 if ($bid_info) {
                     if ($bid_info['bid_price'] >= $val['reserve_price']) {
                         //改变状态
                         $result = $Product->where(array('product_id' => $val['product_id']))->setField('status', 2);
                         $count = $Order->where(array('product_id' => $val['product_id']))->count();
                         if ($result && empty($count)) {
                             // 下单
                             $order_id = create_order_id();
                             $end_time = strtotime('+2 day');
                             $data = array('order_id' => $order_id, 'shop_id' => $val['user_id'], 'user_id' => $bid_info['user_id'], 'product_id' => $val['product_id'], 'price' => $bid_info['bid_price'], 'postage' => $val['postage'], 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'end_time' => $end_time, 'status' => 1);
                             M('Order')->add($data);
                             // 给卖家发
                             $data = array('first' => '你好,【' . $val['product_name'] . '】已经自动结拍,订单已经生成。', 'order_id' => $order_id, 'order_status' => '待支付(等待买家支付)', 'product_name' => $val['product_name'], 'order_price' => $bid_info['bid_price'] + $val['postage'], 'end_time' => '违约有效期:' . date('Y-m-d H:i:s', $end_time));
                             $this->sendOrder(get_shop_info($val['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data);
                             // 给买家发
                             $data['first'] = '你好,【' . $val['product_name'] . '】已经自动结拍,订单已经生成,请在付款有效期内付款。';
                             $this->sendOrder(get_shop_info($bid_info['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data);
                         }
                     } else {
                         // 给卖家发
                         $data = array('first' => '你好,【' . $val['product_name'] . '】已经流拍,出价没有高于或等于保留价。', 'product_id' => $val['product_id'], 'product_name' => $val['product_name'], 'remark' => '流拍时间:' . date('Y-m-d H:i:s', $val['end_time']));
                         $this->sendBid(get_shop_info($val['user_id'], 'openid'), U('Index/product', array('id' => $val['product_id'])), $data);
                         $Product->where(array('product_id' => $val['product_id']))->setField('status', 3);
                     }
                 } else {
                     // 给卖家发
                     $data = array('first' => '你好,【' . $val['product_name'] . '】已经流拍,没有人出价。', 'product_id' => $val['product_id'], 'product_name' => $val['product_name'], 'remark' => '流拍时间:' . date('Y-m-d H:i:s', $val['end_time']));
                     $this->sendBid(get_shop_info($val['user_id'], 'openid'), U('Index/product', array('id' => $val['product_id'])), $data);
                     $Product->where(array('product_id' => $val['product_id']))->setField('status', 3);
                 }
                 break;
             case '3':
                 //秒杀
                 $Product->where(array('product_id' => $val['product_id']))->setField('status', 2);
                 break;
             default:
                 # code...
                 break;
         }
     }
     /* 5分钟提示 */
     $map = array('product_type' => array('in', '1,2'), 'is_send' => 0, 'status' => 1, 'end_time' => array('elt', NOW_TIME + 300));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $value) {
         $Product->where(array('product_id' => $value['product_id']))->setField('is_send', 1);
         $bid_lists = $ProductBid->where(array('product_id' => $value['product_id']))->group('user_id')->select();
         $data = array('touser' => '', 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '5分钟结拍提示', 'description' => '你好,【' . $value['product_name'] . '】还有5分钟结束。' . $money . PHP_EOL . '结拍时间:' . date('Y-m-d H:i:s', $value['end_time']), 'url' => C('WEB_SITE_URL') . U('Index/product', array('id' => $value['product_id'])), 'picurl' => ''))));
         foreach ($bid_lists as $val) {
             $data['touser'] = get_shop_info($val['user_id'], 'openid');
             $this->WX->sendCustomMessage($data);
         }
     }
     /* 3分钟提示 */
     $map = array('product_type' => array('in', '1,2'), 'is_send' => 1, 'status' => 1, 'end_time' => array('elt', NOW_TIME + 180));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $value) {
         $Product->where(array('product_id' => $value['product_id']))->setField('is_send', 2);
         $bid_lists = $ProductBid->where(array('product_id' => $value['product_id']))->group('user_id')->select();
         $data = array('touser' => '', 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '3分钟结拍提示', 'description' => '你好,【' . $value['product_name'] . '】还有3分钟结束。' . $money . PHP_EOL . '结拍时间:' . date('Y-m-d H:i:s', $value['end_time']), 'url' => C('WEB_SITE_URL') . U('Index/product', array('id' => $value['product_id'])), 'picurl' => ''))));
         foreach ($bid_lists as $val) {
             $data['touser'] = get_shop_info($val['user_id'], 'openid');
             $this->WX->sendCustomMessage($data);
         }
     }
     /* 1分钟提示 */
     $map = array('product_type' => array('in', '1,2'), 'is_send' => 2, 'status' => 1, 'end_time' => array('elt', NOW_TIME + 60));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $value) {
         $Product->where(array('product_id' => $value['product_id']))->setField('is_send', 3);
         $bid_lists = $ProductBid->where(array('product_id' => $value['product_id']))->group('user_id')->select();
         $data = array('touser' => get_shop_info($val['user_id'], 'openid'), 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '1分钟结拍提示', 'description' => '你好,【' . $value['product_name'] . '】还有1分钟结束。' . $money . PHP_EOL . '结拍时间:' . date('Y-m-d H:i:s', $value['end_time']), 'url' => C('WEB_SITE_URL') . U('Index/product', array('id' => $value['product_id'])), 'picurl' => ''))));
         foreach ($bid_lists as $val) {
             $data['touser'] = get_shop_info($val['user_id'], 'openid');
             $this->WX->sendCustomMessage($data);
         }
     }
     G('end');
     @unlink(WEB_ROOT . '/cron-0');
     // file_put_contents(WEB_ROOT .'/cron-log.txt', date('Y-m-d H:i:s') . PHP_EOL . G('begin','end') . '0s' . PHP_EOL, FILE_APPEND);
 }