Esempio n. 1
0
 /**
  * 卖家确认发货
  */
 public function sellerConfirmAction($sell_id)
 {
     $sell_order = D('Order')->where(array('id' => $sell_id))->select();
     if (empty($sell_order)) {
         throw new RadaException('系统错误');
     }
     $buy_id = $sell_order['relation_id'];
     $buy_order = D('Order')->find($buy_id);
     D('Order')->startTrans();
     // 更新状态
     $map_1 = array('id' => $buy_id, 'status' => TradeConst::TRADE_STATUS_OPEN);
     $save_1 = array('status' => TradeConst::TRADE_STATUS_DONE, 'relation_id' => $sell_id);
     $res_1 = D('Order')->where($map_1)->save($save_1);
     $map_2 = array('id' => $sell_id, 'status' => TradeConst::TRADE_STATUS_OPEN);
     $save_2 = array('status' => TradeConst::TRADE_STATUS_DONE, 'relation_id' => $buy_id);
     $res_2 = D('Order')->where($map_2)->save($save_2);
     // 划钱
     $res_3 = D('Account')->where(array('user_id' => $sell_order['user_id']))->setDec('coin', $sell_order['num']);
     $res_4 = D('Account')->where(array('user_id' => $buy_order['user_id']))->setInc('coin_tic', $sell_order['num']);
     // 给上级分钱
     if (!$res_1 || !$res_2 || $res_3 || $res_4) {
         D('User')->rollback();
         throw new RadaException('系统错误');
     } else {
         D('User')->commit();
     }
     // 更新用户信息,通知用户去继续交易
     $redis = getRedisEx('TRADE_CACHE');
     $redis->del(TradeConst::TRADE_USER_STATUS_PREFIX . $buy_id);
     $redis->del(TradeConst::TRADE_USER_STATUS_PREFIX . $sell_id);
 }
Esempio n. 2
0
/**
 * 删接口锁
 * @param string $key   锁名字
 */
function unlock_action($key)
{
    $controller_name = strtolower(CONTROLLER_NAME);
    $action_name = strtolower(ACTION_NAME);
    $lock_key = 'system:action_lock:' . $key;
    $redis = getRedisEx('MIXED_CACHE');
    $redis->delete($lock_key);
}
Esempio n. 3
0
 public function testAction()
 {
     $redis = getRedisEx('TRADE_CACHE');
     $index = $redis->lGet('list', 1);
     dump($index);
 }
Esempio n. 4
0
 /**
  * 获取用户信息,优先使用缓存
  * @param unknown $user_id
  */
 public static function getUserInfo($user_id, $refresh = false)
 {
     $redis = getRedisEx('USER_CACHE');
     $info = $redis->hGetAll(self::USER_INFO_PREFIX . $user_id);
     if (empty($info) || $refresh == true) {
         $info = D('User')->find($user_id);
         if (empty($info)) {
             throw new RadaException('没有该用户');
         }
         // 同步到redis
         $redis->hMset(self::USER_INFO_PREFIX . $user_id, $info);
         $redis->expire(self::USER_INFO_PREFIX . $user_id, 864000);
     }
     return $info;
 }