|
@@ -58,43 +58,55 @@ class Cron
|
|
|
public function pai3_api()
|
|
|
{
|
|
|
$id = Dever::input('product_id', 28);
|
|
|
- $data = Dever::db('act/score')->state(array('type' => 4, 'data_id' => $id));
|
|
|
|
|
|
# 购买小刊
|
|
|
$where['product_id'] = $id;
|
|
|
$where['status'] = 2;
|
|
|
- //$this->score = 20;
|
|
|
+ $order_id = Dever::input('order_id');
|
|
|
+ if ($order_id) {
|
|
|
+ $where['order_id'] = $order_id;
|
|
|
+ }
|
|
|
+ $order = Dever::db('journal/order')->state($where);
|
|
|
|
|
|
- # 重建积分排行
|
|
|
- foreach ($data as $k => $v) {
|
|
|
- $where['uid'] = $v['uid'];
|
|
|
- $order = Dever::db('journal/order')->state($where);
|
|
|
-
|
|
|
- $score = 0;
|
|
|
- if ($order) {
|
|
|
- foreach ($order as $k1 => $v1) {
|
|
|
- $score += $this->paiOrder($v1);
|
|
|
- }
|
|
|
+ $user = array();
|
|
|
+ if ($order) {
|
|
|
+ foreach ($order as $k1 => $v1) {
|
|
|
+ $this->paiOrder($v1, $user);
|
|
|
}
|
|
|
- print_r($score);
|
|
|
+ }
|
|
|
|
|
|
- Dever::db('act/score')->update(array('where_id' => $v['id'], 'score' => $score));
|
|
|
+ print_r($user);die;
|
|
|
+
|
|
|
+ # 重建积分排行
|
|
|
+ foreach ($user as $k => $v) {
|
|
|
+ $info = Dever::db('act/score')->one(array('uid' => $v['uid'], 'type' => 4, 'data_id' => $id));
|
|
|
+ if (!$info) {
|
|
|
+ $inesrt['uid'] = $v['uid'];
|
|
|
+ $insert['type'] = 4;
|
|
|
+ $insert['data_id'] = $id;
|
|
|
+ $insert['score'] = $v['score'];
|
|
|
+ Dever::db('act/score')->insert($insert);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 'ok';
|
|
|
|
|
|
}
|
|
|
|
|
|
- private function paiOrder($order)
|
|
|
+ private function paiOrder($order, &$user)
|
|
|
{
|
|
|
- $score = 0;
|
|
|
+ if (!isset($user[$order['uid']])) {
|
|
|
+ $user[$order['uid']] = array();
|
|
|
+ $user[$order['uid']]['uid'] = $order['uid'];
|
|
|
+ $user[$order['uid']]['score'] = 0;
|
|
|
+ }
|
|
|
if ($order['type'] <= 2) {
|
|
|
# 购买小刊、兑换小刊增加积分
|
|
|
if ($order['type'] == 1 && $order['buy_id'] > 0) {
|
|
|
$buy = Dever::db('journal/buy_num')->one($order['buy_id']);
|
|
|
if ($buy) {
|
|
|
$num = $buy['num'];
|
|
|
- $score = $num*20;
|
|
|
+ $user[$order['uid']]['score'] += $num*20;
|
|
|
}
|
|
|
} elseif ($order['type'] == 2 && $order['code']) {
|
|
|
$code = Dever::db('code/info')->one(array('code' => $order['code'], 'state' => 1, 'type' => 3));
|
|
@@ -103,16 +115,15 @@ class Cron
|
|
|
$info = Dever::db('journal/order')->one(array('order_id' => $code['order_id'], 'status' => 2, 'type' => 3));
|
|
|
if ($info) {
|
|
|
$num = $code['product_num'];
|
|
|
- $score = $num*20;
|
|
|
+ $user[$order['uid']]['score'] += $num*20;
|
|
|
}
|
|
|
} elseif ($code['product_num'] > 0) {
|
|
|
$num = $code['product_num'];
|
|
|
- $score = $num*20;
|
|
|
+ $user[$order['uid']]['score'] += $num*20;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return $score;
|
|
|
}
|
|
|
|
|
|
|