Пример #1
0
 /**
  * 保存参赛信息
  *
  * @param integer $match_id
  * @param array $data
  * @return number
  *   -1: match_id为空
  *   -2: 手机号和微信号为空
  *   -3: 手机号已存在
  *   -4: 微信号已存在
  *   -100: 保存失败
  *   >0: 参赛选手ID
  */
 static function joinMatch($match_id, array $data)
 {
     if (empty($match_id)) {
         return -1;
     }
     if (empty($data['mobile']) || empty($data['weixin'])) {
         return -2;
     }
     // 检查是否已经注册过
     if (isset($data['mobile']) && !empty($data['mobile'])) {
         $rs = D()->from("player")->where("`match_id`=%d AND `mobile`='%s' AND `status`<>'D'", $match_id, $data['mobile'])->select("player_id")->result();
         if ($rs) {
             $existed = true;
             return -3;
         }
     }
     if (isset($data['weixin']) && !empty($data['weixin'])) {
         $rs = D()->from("player")->where("`match_id`=%d AND `weixin`='%s' AND `status`<>'D'", $match_id, $data['weixin'])->select("player_id")->result();
         if ($rs) {
             $existed = true;
             return -4;
         }
     }
     $uid = $GLOBALS['user']->uid;
     $data = array_merge(['match_id' => $match_id, 'uid' => $uid], $data, ['jointime' => simphp_time()]);
     $player_id = D()->insert("player", $data);
     return $player_id ?: -100;
 }
Пример #2
0
 public function add(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $nid = $request->post('nid', 0);
         $title = $request->post('title', '');
         $content = $request->post('content', '');
         $img = $request->post('img', '');
         $recommend = $request->post('recommend', 0);
         $sort = $request->post('sort', 0);
         $ret = ['flag' => 'ERR', 'msg' => ''];
         if ('' == $title) {
             $ret['msg'] = '新闻标题';
             $response->sendJSON($ret);
         }
         if ('' == $content) {
             $ret['msg'] = '新闻详情不能为空';
             $response->sendJSON($ret);
         }
         if ('' == $img) {
             $ret['msg'] = '封面不能空';
             $response->sendJSON($ret);
         }
         $info = [];
         if ($nid) {
             $info = News_Model::getInfo($nid);
         }
         $now = simphp_time();
         $uid = $_SESSION['logined_uid'];
         $params = ['title' => $title, 'content' => $content, 'img' => $img, 'recommend' => $recommend, 'sort' => $sort, 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => 'R'];
         if (empty($info)) {
             // new insert
             $ninfo['nid'] = D()->insert('news', $params);
             $ret['flag'] = 'OK';
             $ret['msg'] = '添加成功!';
             $response->sendJSON($ret);
         } else {
             // edit
             unset($params['createdby'], $params['created'], $params['status']);
             D()->update('news', $params, ['nid' => $nid]);
             $ret['flag'] = 'OK';
             $ret['msg'] = '编辑成功!';
             $response->sendJSON($ret);
         }
     } else {
         //
         $nid = $request->arg(1);
         $nid = intval($nid);
         $is_edit = $nid ? TRUE : FALSE;
         $ainfo = $is_edit ? News_Model::getInfo($nid) : [];
         // Node Type
         $node_type = '';
         $this->v->assign('nav_second', $node_type);
         $this->v->set_tplname('mod_news_add');
         $this->v->assign('ninfo', $ainfo)->assign('is_edit', $is_edit);
         $response->send($this->v);
     }
 }
Пример #3
0
 /**
  * 插入订单动作日志
  */
 static function order_action_log($order_id, array $insert_data)
 {
     if (empty($order_id)) {
         return false;
     }
     $oinfo = D()->get_one("SELECT `order_id`,`order_status`,`pay_status` FROM {order_info} WHERE `order_id`=%d", $order_id);
     $init_data = ['order_id' => $order_id, 'action_user' => 'buyer', 'order_status' => $oinfo['order_status'], 'shipping_status' => SS_RECEIVED, 'pay_status' => $oinfo['pay_status'], 'action_place' => 0, 'action_note' => '', 'log_time' => simphp_time()];
     $insert_data = array_merge($init_data, $insert_data);
     $rid = D()->insert('order_action', $insert_data, true, false);
     return $rid;
 }
Пример #4
0
 public static function delete($ids)
 {
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $idstr = implode(',', $ids);
     if ($idstr) {
         $now = simphp_time();
         //~ update table {channel}
         D()->query("UPDATE `{news}` SET `status`='D',`changedby`=%d,`changed`=%d WHERE `nid` IN (%s)", $_SESSION['logined_uid'], $now, $idstr);
         return $ids;
     }
     return [];
 }
Пример #5
0
 /**
  * new insert or update media table
  * @return boolean
  */
 public static function save($data = [], $mid = 0)
 {
     if (!$mid) {
         //edit
         $data['created'] = simphp_time();
         $data['changed'] = $data['created'];
         $data['status'] = 'N';
         return D()->insert_table('media', $data);
     } else {
         //insert
         $data['changed'] = simphp_time();
         D()->update_table('media', $data, ['mid' => $mid]);
         return $mid;
     }
 }
Пример #6
0
 /**
  * 提交地址
  * 
  * @param Request $request
  * @param Response $response
  */
 function post_address(Request $request, Response $response)
 {
     $uid = $GLOBALS['user']->uid;
     if ($request->is_post()) {
         //送花奖励阶梯
         $sendmoney_phases = [30, 50, 100];
         $address_id = $request->post('address_id', 0);
         $match_id = $request->post('match_id', 0);
         $player_id = $request->post('player_id', 0);
         $order_id = $request->post('order_id', 0);
         $sendmoney = $request->post('sendmoney', 0);
         $backurl = $request->post('backurl', 0);
         $consignee = $request->post('consignee', '');
         $mobile = $request->post('mobile', '');
         $province = $request->post('province', 0);
         $city = $request->post('city', 0);
         $address = $request->post('address', '');
         $zipcode = $request->post('zipcode', '');
         $res = ['flag' => 'FAIL', 'msg' => '', 'match_id' => $match_id, 'backurl' => $backurl];
         if (empty($uid)) {
             $res['msg'] = '未登录,请先登录';
             $response->sendJSON($res);
         }
         if ('' == $consignee) {
             $res['msg'] = '姓名不能为空';
             $response->sendJSON($res);
         }
         if ('' == $mobile) {
             $res['msg'] = '手机不能为空';
             $response->sendJSON($res);
         } elseif (!preg_match('/^\\d{11,14}$/', $mobile)) {
             $res['msg'] = '手机号码不正确';
             $response->sendJSON($res);
         }
         if (empty($province)) {
             $res['msg'] = '身份地址不能为空';
             $response->sendJSON($res);
         }
         $province_name = Match_Model::getLocationName($province);
         if (empty($city)) {
             $res['msg'] = '城市地址不能为空';
             $response->sendJSON($res);
         }
         $city_name = Match_Model::getLocationName($city);
         if ('' == $address) {
             $res['msg'] = '详细地址不能为空';
             $response->sendJSON($res);
         }
         if ('' != $zipcode && !preg_match('/^\\d{6}$/', $zipcode)) {
             $res['msg'] = '邮政编码不正确';
             $response->sendJSON($res);
         }
         $tbname = 'member_address';
         $tbdata = ['address_name' => '', 'user_id' => $uid, 'consignee' => $consignee, 'country' => 2, 'country_name' => '中国', 'province' => $province, 'province_name' => $province_name, 'city' => $city, 'city_name' => $city_name, 'district' => 0, 'district_name' => '', 'address' => $address, 'zipcode' => $zipcode, 'mobile' => $mobile];
         if (!$address_id) {
             // Insert mode
             $address_id = D()->insert($tbname, $tbdata);
         } else {
             // Edit mode
             D()->update($tbname, $tbdata, ['address_id' => $address_id]);
         }
         //送奖品记录
         if ($address_id && $sendmoney >= $sendmoney_phases[0] && $player_id && $order_id) {
             $phasemoney = $sendmoney_phases[0];
             if ($sendmoney >= $sendmoney_phases[1] && $sendmoney < $sendmoney_phases[2]) {
                 $phasemoney = $sendmoney_phases[1];
             } elseif ($sendmoney >= $sendmoney_phases[2]) {
                 $phasemoney = $sendmoney_phases[2];
             }
             $tbdata = ['user_id' => $uid, 'address_id' => $address_id, 'player_id' => $player_id, 'order_id' => $order_id, 'phase_money' => $phasemoney, 'true_money' => $sendmoney, 'timeline' => simphp_time()];
             $rid = D()->from("member_giftpay")->where("`user_id`=%d AND `player_id`=%d AND `order_id`=%d", $uid, $player_id, $order_id)->select('`rid`')->result();
             if (!$rid) {
                 //一个订单只有没有生成过记录时才记录,避免重复
                 D()->insert('member_giftpay', $tbdata);
             } else {
                 $res['flag'] = 'SUC';
                 $res['msg'] = '当前订单之前申请过礼物,不能重复申请';
                 $response->sendJSON($res);
             }
         }
         $res['flag'] = 'SUC';
         $res['msg'] = '地址保存成功!';
         $response->sendJSON($res);
     } else {
         $this->v->set_tplname('mod_match_post_address');
         $this->v->set_page_render_mode(View::RENDER_MODE_GENERAL);
         $this->nav_flag1 = 'match_address';
         $this->topnav_no = 1;
         $match_id = $request->arg(1);
         $sendmoney = $request->get('sendmoney', 0);
         $player_id = $request->get('player_id', 0);
         $order_id = $request->get('order_id', 0);
         $backurl = $request->get('backurl', '');
         $this->v->assign('match_id', $match_id);
         $this->v->assign('player_id', $player_id);
         $this->v->assign('order_id', $order_id);
         $this->v->assign('sendmoney', $sendmoney);
         $this->v->assign('backurl', $backurl);
         $player_info = Match_Model::getPlayerInfo($player_id);
         $this->v->assign('player_info', $player_info);
         $user_address = Match_Model::getUserAddress($uid);
         $this->v->assign('user_address', $user_address);
         $province = Match_Model::getProvinces();
         $this->v->assign('province', $province);
         $city_html = '<option value="0">选择城市▼</option>';
         if (!empty($user_address)) {
             $cities = Match_Model::getCities($user_address['province']);
             $selected = '';
             foreach ($cities as $loc) {
                 if ($loc['locaid'] == $user_address['city']) {
                     $selected = ' selected="selected"';
                 } else {
                     $selected = '';
                 }
                 $city_html .= '<option value="' . $loc['locaid'] . '"' . $selected . '>' . $loc['location'] . '</option>';
             }
         }
         $this->v->assign('city_html', $city_html);
         $seo = ['title' => '地址上传', 'keyword' => '', 'desc' => ''];
         $this->v->assign('seo', $seo);
         $response->send($this->v);
     }
 }
Пример #7
0
 /**
  * action 'add'
  * @param Request $request
  * @param Response $response
  */
 public function add(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $nid = $request->post('nid', 0);
         $ntype = $request->post('ntype');
         $title = $request->post('title', '');
         $thumb_url = $request->post('thumb_url', '');
         $match_type = $request->post('match_type', '');
         $start_date = $request->post('start_date', '');
         $end_date = $request->post('end_date', '');
         $keyword = $request->post('keyword', '');
         $slogan = $request->post('slogan', '');
         $content = $request->post('content', '');
         $content_dt = $request->post('content_detail', '');
         $status = $request->post('status', 'R');
         $ret = ['flag' => 'ERR', 'msg' => ''];
         if ('match' == $ntype) {
             if ('' == $title) {
                 $ret['msg'] = '标题不能为空';
                 $response->sendJSON($ret);
             } elseif ('' == $thumb_url) {
                 $ret['msg'] = '主图片不能为空';
                 $response->sendJSON($ret);
             }
             $match_types = Node::getMatchTypes();
             if (!in_array($match_type, array_keys($match_types))) {
                 $match_type = 'bs';
             }
         }
         $status_set = Node::getStatus();
         if (!in_array($status, array_keys($status_set))) {
             $status = 'R';
         }
         $ninfo = [];
         if ($nid) {
             $ninfo = Node::getInfo($nid);
             if (empty($ninfo)) {
                 $ret['msg'] = "Node(nid={$nid})不存在";
                 $response->sendJSON($ret);
             }
         }
         $uid = $_SESSION['logined_uid'];
         if (empty($uid)) {
             $ret['msg'] = "未登录,请重新登录";
             $response->sendJSON($ret);
         }
         $now = simphp_time();
         $params = ['ntype' => $ntype, 'title' => $title, 'content' => $content, 'keyword' => $keyword, 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => $status];
         $allowed_ntypes = C('env.allowed_nodetypes');
         if (empty($ninfo)) {
             // new insert
             $ninfo['nid'] = D()->insert('node', $params);
             if ($ninfo['nid'] && in_array($ntype, $allowed_ntypes) && 'base' != $ntype) {
                 $params_ext = ['enid' => $ninfo['nid']];
                 switch ($ntype) {
                     case 'match':
                         $params_ext['match_type'] = $match_type;
                         $params_ext['thumb_url'] = $thumb_url;
                         $params_ext['slogan'] = $slogan;
                         $params_ext['start_date'] = $start_date;
                         $params_ext['end_date'] = $end_date;
                         $params_ext['content_detail'] = $content_dt;
                         break;
                 }
                 D()->insert('node_' . $ntype, $params_ext);
             }
             $ret['flag'] = 'OK';
             $ret['msg'] = '添加成功!';
             $response->sendJSON($ret);
         } else {
             // edit
             unset($params['createdby'], $params['created']);
             D()->update('node', $params, ['nid' => $nid]);
             if (D()->affected_rows() && in_array($ntype, $allowed_ntypes) && 'base' != $ntype) {
                 $params_ext = [];
                 switch ($ntype) {
                     case 'match':
                         $params_ext['match_type'] = $match_type;
                         $params_ext['thumb_url'] = $thumb_url;
                         $params_ext['slogan'] = $slogan;
                         $params_ext['start_date'] = $start_date;
                         $params_ext['end_date'] = $end_date;
                         $params_ext['content_detail'] = $content_dt;
                         break;
                 }
                 D()->update('node_' . $ntype, $params_ext, ['enid' => $nid]);
             }
             $ret['flag'] = 'OK';
             $ret['msg'] = '编辑成功!';
             $response->sendJSON($ret);
         }
     } else {
         // GET request
         // Node Info
         $nid = $request->arg(1);
         $nid = intval($nid);
         $is_edit = $nid ? TRUE : FALSE;
         $ninfo = $is_edit ? Node::getInfo($nid) : [];
         // Node Type
         $node_type = '';
         if (!$is_edit) {
             $node_type = $request->arg(2);
             $allowed_ntypes = C('env.allowed_nodetypes');
             if (!in_array($node_type, $allowed_ntypes)) {
                 $node_type = 'base';
             }
         } else {
             $node_type = $ninfo['ntype'];
         }
         $this->v->assign('node_type', $node_type);
         $this->v->assign('nav_second', $node_type);
         // Node status
         $status_set = Node::getStatus();
         $this->v->assign('status_set', $status_set);
         // Extra node info
         switch ($node_type) {
             case 'match':
                 $match_types = Node::getMatchTypes();
                 $this->v->assign('match_types', $match_types);
                 break;
         }
         $this->v->set_tplname('mod_node_add');
         $this->v->assign('ninfo', $ninfo)->assign('is_edit', $is_edit);
         $response->send($this->v);
     }
 }
Пример #8
0
 /**
  * 订单确认
  *
  * @param Request $request
  * @param Response $response
  */
 public function order_submit(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $ret = ['flag' => 'FAIL', 'msg' => '订单提交失败'];
         $uid = $GLOBALS['user']->uid;
         if (!$uid) {
             $ret['msg'] = '未登录, 请先在微信登录';
             $response->sendJSON($ret);
         }
         $player_id = $request->post('player_id', 0);
         $goods_type = $request->post('goods_type', 'flower');
         $goods_amount = $request->post('amount', 0);
         $pay_id = 2;
         //2是微信支付,见ec payment表
         // 检查数据
         // 参赛者
         if (!Node::playerExisted($player_id)) {
             $ret['msg'] = "参赛者不存在(player_id={$player_id})";
             $response->sendJSON($ret);
         }
         // 数量
         $goods_amount = intval($goods_amount);
         if (!$goods_amount) {
             $ret['msg'] = 'flower' == $goods_type ? '送花数量不能为空' : '送吻数量不能为空';
             $response->sendJSON($ret);
         }
         $order_amount = $goods_amount;
         // 支付信息
         $pay_info = Goods::getPaymentInfo($pay_id);
         if (empty($pay_info)) {
             $ret['msg'] = '该支付方式暂不可用,请重新选择';
             $response->sendJSON($ret);
         }
         $order_sn = Fn::gen_order_no();
         $order = ['order_sn' => $order_sn, 'user_id' => $uid, 'order_status' => OS_UNCONFIRMED, 'pay_status' => PS_UNPAYED, 'pay_id' => $pay_info['pay_id'], 'pay_name' => $pay_info['pay_name'], 'player_id' => $player_id, 'goods_type' => $goods_type, 'goods_amount' => $goods_amount, 'order_amount' => $order_amount, 'money_paid' => 0, 'add_time' => simphp_time()];
         $order_id = D()->insert("order_info", $order);
         if ($order_id) {
             //订单表生成成功
             $order['order_id'] = $order_id;
             $true_amount = $order_amount;
             // 处理表 pay_log
             Trade_Model::insertPayLog($order_id, $order_sn, $true_amount, PAY_ORDER);
             $jsApiParams = '';
             if (2 == $pay_info['pay_id']) {
                 //微信支付
                 $jsApiParams = Wxpay::unifiedOrder($order, $GLOBALS['user']->openid);
             }
             $ret = ['flag' => 'SUC', 'msg' => '订单提交成功', 'order_id' => $order_id, 'order_sn' => $order_sn, 'js_api_params' => json_decode($jsApiParams)];
             $response->sendJSON($ret);
         } else {
             $ret['msg'] = '订单生成失败,请返回购物车重新添加';
             $response->sendJSON($ret);
         }
     } else {
         $this->v->set_tplname('mod_trade_order_submit');
         $this->nav_flag1 = 'order';
         $this->nav_flag2 = 'order_submit';
         $this->nav_no = 0;
         if ($request->is_hashreq()) {
         } else {
         }
         $response->send($this->v);
     }
 }
Пример #9
0
 /**
  * 收藏商品
  * 
  * @return string
  *   'collected'   : 之前已收藏
  *   'new_collect' : 成功新收藏
  *   'collect_fail': 收藏失败
  */
 static function goodsCollecting($goods_id, $ec_user_id)
 {
     if (!$ec_user_id) {
         $ec_user_id = $GLOBALS['user']->ec_user_id;
     }
     $ret = 'collected';
     if (!self::isCollected($goods_id, $ec_user_id)) {
         //未收藏
         $ins = ['user_id' => $ec_user_id, 'goods_id' => $goods_id, 'add_time' => simphp_time(), 'is_attention' => 0];
         $rid = D()->insert(ectable('collect_goods'), $ins, true, true);
         if ($rid) {
             self::changeGoodsCollectCnt($goods_id, 1);
             $ret = 'new_collect';
         } else {
             $ret = 'collect_fail';
         }
     }
     return $ret;
 }
Пример #10
0
 /**
  *
  * @param string $act, 'vote','flower','kiss'
  * @param integer $player_id
  * @param integer $uid
  * @param integer $inc
  * @param boolean $nocheck,是否不检查
  * @param boolean $norecord,是否不记录
  * @param array $extra,额外参数记录
  * @return number
  *   -11: vote超过了最大次数(5)
  *   -12: vote时间间隔没超过120分钟
  *   -13: 投票太频繁
  *   -14: 投票已截止
  *  -100: 操作失败
  */
 static function action($act, $player_id, $uid, $inc = 1, $nocheck = FALSE, $norecord = FALSE, $extra = array())
 {
     $now = simphp_time();
     $votedcnt = 0;
     $maxvotenum = 5;
     //一个用户一天可以对每个女神投5次票,可连续投
     $voteinterval = 60 * 60 * 2;
     //投票间隔限制(单位:秒)
     $spaminterval = 2;
     //作弊检测时间(单位:秒)
     $maybespam = 0;
     //可能作弊标志
     $limitvotetime = strtotime('2015-12-20 23:55:00');
     $stopvotetime = strtotime('2015-12-21 00:00:00');
     if ('vote' == $act && !$nocheck) {
         if ($now > $stopvotetime) {
             return -14;
         }
         $today_start = shorttotime('jt');
         $today_end = shorttotime('mt');
         //查找当天已经投的次数
         $votedcnt = D()->from("action")->where("`player_id`=%d AND `action`='%s' AND `uid`=%d AND `timeline`>=%d AND `timeline`<%d", $player_id, $act, $uid, $today_start, $today_end)->select("COUNT(`aid`) AS cnt")->result();
         if ($votedcnt >= $maxvotenum) {
             return -11;
         }
         //查找前一次投票时间
         $now = simphp_time();
         $latest = D()->from("action")->where("`action`='%s' AND `player_id`=%d AND `uid`=%d", $act, $player_id, $uid)->select("MAX(`timeline`) AS maxacttime")->result();
         $diff = $now - $latest;
         if ($diff < $spaminterval) {
             $maybespam = $spaminterval - $diff;
             //return -13;
         }
         if (isset($extra['maybe_spam']) && $extra['maybe_spam']) {
             $maybespam = 100;
         }
         /*
         if ($diff < $voteinterval) {
           return -12;
         }
         */
     }
     if (in_array($act, ['vote', 'flower', 'kiss'])) {
         $aid = 0;
         if (!$norecord) {
             $aid = D()->insert("action", ['action' => $act, 'player_id' => $player_id, 'inc' => $inc, 'uid' => $uid, 'timeline' => $now, 'spam' => $maybespam]);
         }
         if ($norecord || $aid) {
             //更新player投票数
             if ($now < $stopvotetime) {
                 D()->query("UPDATE {player} SET {$act}cnt={$act}cnt+%d WHERE player_id=%d", $inc, $player_id);
             }
             //更新node总投票数
             $match_id = D()->from("player")->where("player_id=%d", $player_id)->select("match_id")->result();
             D()->query("UPDATE {node} SET {$act}cnt={$act}cnt+%d WHERE nid=%d", $inc, $match_id);
             if ($act == 'vote') {
                 $player_stage = D()->from("player")->where("player_id=%d", $player_id)->select("`stage`")->result();
                 if ($now < $stopvotetime && in_array($player_stage, ['1', '2'])) {
                     //同步更新晋级赛程的统计票数字段
                     if ($now < $limitvotetime || isset($extra['from']) && in_array($extra['from'], ['sendflower', 'admin'])) {
                         D()->query("UPDATE {player} SET votecnt{$player_stage}=votecnt{$player_stage}+%d WHERE player_id=%d", $inc, $player_id);
                     } else {
                         if (0 == $votedcnt) {
                             //最后十分钟仅保留1人1票
                             D()->query("UPDATE {player} SET votecnt{$player_stage}=votecnt{$player_stage}+%d WHERE player_id=%d", $inc, $player_id);
                         }
                     }
                 }
                 if (!$nocheck) {
                     return $maxvotenum - $votedcnt - $inc;
                     //需检查限制的,返回当前剩余可投票数;否则留最后默认返回$aid
                 }
             } elseif ($act == 'flower') {
                 //规则:
                 // 1、一枝花抵两票
                 // 2、数量不限、时间不限
                 // 送票(x2)
                 self::action('vote', $player_id, $uid, $inc * 2, TRUE, TRUE, ['from' => 'sendflower']);
             } elseif ($act == 'kiss') {
             }
             return $aid;
             //默认返回动作id
         }
     }
     return -100;
 }
Пример #11
0
 public static function importMusic($source, $url = '')
 {
     switch ($source) {
         case 'hnyd':
             //$data[] = ['title'=>'','singer_name'=>'','source_id'=>'','music_url'=>''];
             $data = self::importMusic_hnyd($url);
             //保存数据
             foreach ($data as $val) {
                 //查询歌曲是否已存在
                 $hash = md5($val['music_url']);
                 $sql = "SELECT * FROM {node_music} WHERE music_url_hash='%s' ";
                 //exit("SELECT * FROM {node_music} WHERE music_url_hash='{$hash}' ");
                 if (D()->get_one($sql, $hash)) {
                     break;
                 }
                 $now = simphp_time();
                 $uid = $_SESSION['logined_uid'];
                 $params = ['type_id' => 'music', 'cate_id' => 0, 'title' => $val['title'], 'content' => '', 'keyword' => '', 'tag' => '', 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => 'S', 'recommend' => 0, 'sort' => 0];
                 $nid = D()->insert('node', $params);
                 if ($nid > 0) {
                     $params_ext = ['tnid' => $nid, 'source_id' => $source, 'singer_name' => $val['singer_name'], 'singer_link' => '', 'singer_fans' => 0, 'icon_url' => '', 'bg_url' => '', 'music_url' => $val['music_url'], 'music_url_hash' => $hash];
                     D()->insert('node_music', $params_ext);
                 }
             }
             break;
         default:
             # code...
             break;
     }
 }
Пример #12
0
 /**
  * action 'notify'
  * 微信支付统一下订单回调
  *
  * @param Request $request
  * @param Response $response
  */
 public function notify(Request $request, Response $response)
 {
     Wxpay::nofify(function ($data, &$msg) {
         //trace_debug('wxpay_notify_data', $data);
         //trace_debug('wxpay_notify_msg', $msg);
         if ('OK' == $msg) {
             // 成功合法的订单
             // 关注的数据
             $openid = $data['openid'];
             //用户openid
             $is_subscribe = $data['is_subscribe'];
             //是否关注公众账号:'Y' or 'N'
             $total_fee = $data['total_fee'];
             //订单总金额,单位为分
             $bank_type = $data['bank_type'];
             //付款银行
             $transaction_id = $data['transaction_id'];
             //微信支付订单号
             $order_sn = $data['out_trade_no'];
             //自身订单号
             $attach = isset($data['attach']) ? $data['attach'] : '';
             //商家自定义数据,原样返回
             $time_end = $data['time_end'];
             //支付完成时间,格式为yyyyMMddHHmmss,如:20141030133525
             $time_end = Fn::to_timestamp($time_end);
             //对日志表"写锁定",避免其他线程进入干扰(这时其他线程对表pay_log的读写都要等待)
             $tb_paylog = C('storage.mysql-config.tablePrefix') . 'pay_log';
             D()->lock_tables($tb_paylog, DB::LOCK_WRITE, '', TRUE);
             //检查支付日志表,以确定订单是否存在(之所以用日志表而不是主表order_info,是为了在锁表期间不阻塞到前台访问频繁的主表)
             $pay_log = D()->from($tb_paylog, DB::WRITABLE)->where(['order_sn' => $order_sn])->select()->get_one();
             if (empty($pay_log)) {
                 $msg = '订单号不存在';
                 D()->unlock_tables();
                 // 解锁
                 return false;
             }
             $order_id = $pay_log['order_id'];
             //检查支付金额是否正确
             if (intval($pay_log['order_amount'] * 100) != $total_fee) {
                 $msg = '金额不对';
                 D()->unlock_tables();
                 // 解锁
                 return false;
             }
             //检查订单状态
             if (!$pay_log['is_paid']) {
                 //未付款
                 //更新pay_log
                 D()->update($tb_paylog, ['is_paid' => 1], ['order_id' => $order_id], true);
                 // 更新完立马解锁
                 D()->unlock_tables();
                 //立马修改订单状态为已付款
                 $updata = ['pay_trade_no' => $transaction_id, 'order_status' => OS_CONFIRMED, 'confirm_time' => simphp_time(), 'pay_status' => PS_PAYED, 'pay_time' => simphp_time($time_end), 'money_paid' => $pay_log['order_amount'], 'order_amount' => 0, 'pay_data2' => json_encode($data)];
                 D()->update('order_info', $updata, ['order_id' => $order_id]);
                 //记录订单操作记录
                 Order::order_action_log($order_id, ['action_note' => '用户支付']);
                 //更新订单下所有商品的"订单数"
                 //Goods::updateGoodsOrderCntByOrderid($order_id);
                 //订单成功后的操作,如送分、送票等
                 Order::order_success_after($order_id);
             } else {
                 D()->unlock_tables();
                 // 解锁
             }
             return true;
         }
         return false;
     });
 }
Пример #13
0
 static function deletePlayers($ids)
 {
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $idstr = implode(',', $ids);
     if ($idstr) {
         $now = simphp_time();
         //~ update table {channel}
         D()->query("UPDATE `{player}` SET `status`='D' WHERE `player_id` IN (%s)", $idstr);
         //~ update table {node}
         $nids = self::getMatchIdsByPlayerIds($idstr);
         if (!empty($nids)) {
             foreach ($nids as $nid) {
                 self::updateNodeStat($nid);
             }
         }
         return $ids;
     }
     return [];
 }
Пример #14
0
 public function add(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $aid = $request->post('aid', 0);
         $title = $request->post('title', '');
         $content = $request->post('content', '');
         $img = $request->post('img', '');
         $start_time = $request->post('start_time', '');
         $end_time = $request->post('end_time', '');
         $link = $request->post('link', '');
         $tpl = $request->post('tpl', 0);
         $ret = ['flag' => 'ERR', 'msg' => ''];
         if ('' == $title) {
             $ret['msg'] = '活动标题不能为空';
             $response->sendJSON($ret);
         }
         if ('' == $img) {
             $ret['msg'] = '活动封面不能为空';
             $response->sendJSON($ret);
         }
         /*else if (!preg_match('!^http://.{4,}!', $img)) {
             $ret['msg'] = '活动封面地址无效';
             $response->sendJSON($ret);
           }*/
         if ('' == $content) {
             $ret['msg'] = '活动详情不能为空';
             $response->sendJSON($ret);
         }
         if (!empty($start_time) && strlen($start_time) != 19) {
             $ret['msg'] = '活动开始时间格式不正确';
             $response->sendJSON($ret);
         }
         if (!empty($end_time) && strlen($end_time) != 19) {
             $ret['msg'] = '活动结束时间格式不正确';
             $response->sendJSON($ret);
         }
         $aid = intval($aid);
         $start_time = strtotime($start_time);
         $end_time = strtotime($end_time);
         $start_time = intval($start_time);
         $end_time = intval($end_time);
         $info = [];
         if ($aid) {
             $info = Activity_Model::getInfo($aid);
         }
         $now = simphp_time();
         $uid = $_SESSION['logined_uid'];
         $params = ['title' => $title, 'tpl' => $tpl, 'content' => $content, 'img' => $img, 'start_time' => $start_time, 'end_time' => $end_time, 'link' => $link, 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => 'R'];
         if (empty($info)) {
             // new insert
             $ninfo['aid'] = D()->insert('activity', $params);
             $ret['flag'] = 'OK';
             $ret['msg'] = '添加成功!';
             $response->sendJSON($ret);
         } else {
             // edit
             unset($params['createdby'], $params['created'], $params['status']);
             D()->update('activity', $params, ['aid' => $aid]);
             $ret['flag'] = 'OK';
             $ret['msg'] = '编辑成功!';
             $response->sendJSON($ret);
         }
     } else {
         //
         $aid = $request->arg(1);
         $aid = intval($aid);
         $is_edit = $aid ? TRUE : FALSE;
         $ainfo = $is_edit ? Activity_Model::getInfo($aid) : [];
         // Node Type
         $node_type = '';
         $this->v->assign('nav_second', $node_type);
         $this->v->set_tplname('mod_activity_add');
         $this->v->assign('ninfo', $ainfo)->assign('is_edit', $is_edit);
         $response->send($this->v);
     }
 }
Пример #15
0
 /**
  * 作业主入口
  */
 public function main($argc, $argv)
 {
     $wx = new Weixin();
     $total = $wx->getMaterialCount();
     //按素材类型逐个获取列表
     foreach (self::$type_set as $type) {
         $type_total = $total[$type . '_count'];
         $offset = 0;
         $count = $type_total > self::MAX_COUNT ? self::MAX_COUNT : $type_total;
         $this->log("Type={$type}...");
         do {
             $ret = $wx->getMaterialList($type, $offset, $count);
             if (empty($ret) || $ret['item_count'] == 0) {
                 break;
             }
             $curr_latest_uptime = $ret['item'][0]['update_time'];
             if ($curr_latest_uptime == $this->check_latest_uptime($type)) {
                 break;
                 //如果当前返回的最新时间戳跟本地的最大时间戳一样,则不需要处理了(仅在第一次检查)
             }
             // 循环获取各个素材
             foreach ($ret['item'] as $it) {
                 $data_base = ['type' => $type, 'media_id' => $it['media_id'], 'show_cover_pic' => 0, 'update_time' => $it['update_time'], 'is_multiple' => 0, 'add_time' => simphp_time()];
                 if ($type == 'news') {
                     //图文消息相比其他消息复杂特殊
                     if (!empty($it['content']) && !empty($it['content']['news_item'])) {
                         $multi_count = count($it['content']['news_item']);
                         if ($multi_count > 1) {
                             //多图文信息
                             $data_base['is_multiple'] = 1;
                         }
                         foreach ($it['content']['news_item'] as $cont) {
                             $sign = $this->media_sign($type, $it['media_id'], $cont['url']);
                             if (!$this->can_insert($sign) && !$this->need_update($sign, $it['update_time'])) {
                                 break 3;
                                 // 记录存在且时间未更新,则不需要处理了,直接跳出主循环(在这里是3层)
                             }
                             $data = [];
                             $data['media_sign'] = $sign;
                             $data['title'] = $cont['title'];
                             $data['author'] = $cont['author'];
                             $data['digest'] = $cont['digest'];
                             $data['content'] = $cont['content'];
                             $data['content_source_url'] = $cont['content_source_url'];
                             $data['url'] = $cont['url'];
                             $data['thumb_media_id'] = $cont['thumb_media_id'];
                             $data['show_cover_pic'] = $cont['show_cover_pic'];
                             $data = array_merge($data_base, $data);
                             $nid = $this->save_material($data);
                             // 下载图片并保存
                             if ($nid) {
                                 $outfile = '';
                                 if ($wx->getMaterial($cont['thumb_media_id'], $outfile)) {
                                     if ($outfile) {
                                         $this->save_thumb_media_url($nid, $outfile);
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     $sign = $this->media_sign($type, $it['media_id'], $it['url']);
                     if (!$this->can_insert($sign) && !$this->need_update($sign, $it['update_time'])) {
                         break 2;
                         // 记录存在且时间未更新,则不需要处理了,直接跳出主循环(在这里是2层)
                     }
                     $data = [];
                     $data['media_sign'] = $sign;
                     $data['name'] = $it['name'];
                     $data['url'] = $it['url'];
                     $data = array_merge($data_base, $data);
                     $this->save_material($data);
                 }
             }
             //END foreach ($ret['item'] AS $it)
             $offset += $ret['item_count'];
             //改写偏移
         } while ($offset < $type_total);
     }
     //END foreach (self::$type_set AS $type)
 }
Пример #16
0
 /**
  * 设置本地登录信息
  * 
  * @param integer $uid
  */
 public static function setLocalLogin($uid)
 {
     if (!$uid) {
         return;
     }
     global $user;
     //设置登录session uid
     $user->uid = $uid;
     //设置首页分页起始页
     $_SESSION['mark_pageno'] = 1;
     //更新登录记录
     self::updateUser(['lastip' => Request::ip(), 'lasttime' => simphp_time()], $uid);
     /*
     //更新ecshop数据表users
     $ecdata  = ['last_login' => simphp_time(), 'last_ip' => Request::ip()];
     $ecwhere = ['member_platform' => APP_PLATFORM, 'member_id' => $uid];
     D()->update(ectable('users'), $ecdata, $ecwhere, TRUE);
     */
 }