public function hongBao() { if (!C('HONG_BAO_ALLOW')) { $this->resultError('未开启拆红包功能'); } 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')); } // $this->resultError('end', '', U('Setting/index')); $shop_id = I('shop_id', 0, 'intval'); if (!$shop_id) { $this->resultError('无效店铺参数'); } $Hongbao = M('Hongbao'); $map = array('shop_id' => $shop_id, 'user_id' => $this->user_info['user_id'], 'create_time' => array('gt', strtotime(date('Ymd'))), 'status' => 1); $count = $Hongbao->where($map)->count(); if ($count) { $this->resultError('每天每个店铺只能领取一次'); } $moneys = explode('-', C('HONG_BAO_MONEY')); if (count($moneys) == 1) { $money = $moneys[0]; } elseif (count($moneys) == 2) { $money = mt_rand($moneys[0], $moneys[1]); } $data = array('user_id' => $this->user_info['user_id'], 'shop_id' => $shop_id, 'money' => $money, 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'status' => 1); $result = $Hongbao->add($data); if ($result) { fund_inc($this->user_info['user_id'], $money, '拆红包'); // 给卖家发 // $data = array( // 'first' => '你好,【'. $this->user_info['user_name'] .'】获得¥'. $money, // 'product_id' => $result, // 'product_name' => '抢红包活动', // 'remark' => '抢红包时间:' . date('Y-m-d H:i:s') // ); // $this->sendBid($this->user_info['openid'], U('User/index'), $data); $shop_data = array('touser' => $this->user_info['openid'], 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '抢购红包成功提示', 'description' => '你好,【' . $this->user_info['user_name'] . '】获得¥' . $money . PHP_EOL . '抢红包时间:' . date('Y-m-d H:i:s'), 'url' => C('WEB_SITE_URL') . U('User/index'), 'picurl' => '')))); $this->WX->sendCustomMessage($shop_data); $this->resultSuccess('抢红包获得¥' . $money); } else { $this->resultError(); } }
public function change($id, $status) { if (empty($id) || empty($status)) { $this->error('参数错误...'); } $data = array('id' => $id, 'status' => $status, 'update_time' => NOW_TIME); if ($this->db->save($data)) { switch ($status) { case '2': $info = $this->db->find($id); fund_inc($info['user_id'], $info['money'], '提现拒绝'); break; case '3': // TODO: 企业转账接口 break; } $this->success('成功'); } else { $this->error('失败!'); } }
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); }
public function qianShou() { $order_id = I('order_id'); if (empty($order_id)) { $this->resultError('订单号不能为空'); } $order_info = M('Order')->find($order_id); if (!$order_info) { $this->resultError('订单不存在...'); } $map = array('user_id' => $this->user_info['user_id'], 'order_id' => $order_id); $data = array('status' => 4, 'update_time' => NOW_TIME); $result = M('Order')->where($map)->save($data); if ($result) { // 给卖家发 $order_info['product_name'] = get_product_info($order_info['product_id']); $data = array('first' => '你好,【' . $order_info['product_name'] . '】订单已经签收,订单顺利完成。', 'order_id' => $order_id, 'order_status' => '已签收(订单完成)', 'product_name' => $order_info['product_name'], 'end_time' => '签收时间:' . date('Y-m-d H:i:s')); $this->sendOrder(get_shop_info($order_info['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data); $this->sendOrder(get_shop_info($order_info['shop_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data); // 为商家充值 fund_inc($order_info['shop_id'], $order_info['price'] + $order_info['postage'], '买卖交易'); $this->resultSuccess('签收成功', '', U('Order/index', array('order_id' => $order_id))); } else { $this->resultError('网络异常...'); } }