diff --git a/app/common/dao/store/order/StoreOrderHotDao.php b/app/common/dao/store/order/StoreOrderHotDao.php index d75f67e..a70e18e 100644 --- a/app/common/dao/store/order/StoreOrderHotDao.php +++ b/app/common/dao/store/order/StoreOrderHotDao.php @@ -24,4 +24,8 @@ class StoreOrderHotDao extends BaseDao return StoreOrderHot::class; } + public function getList($where){ + return StoreOrderHot::where($where)->whereRaw('total > current')->select(); + } + } diff --git a/app/common/repositories/store/order/StoreOrderHotRepository.php b/app/common/repositories/store/order/StoreOrderHotRepository.php index fa24be4..4e57732 100644 --- a/app/common/repositories/store/order/StoreOrderHotRepository.php +++ b/app/common/repositories/store/order/StoreOrderHotRepository.php @@ -38,7 +38,7 @@ class StoreOrderHotRepository extends BaseRepository public function getList($where){ - return $this->dao->selectWhere($where); + return $this->dao->getList($where); } } diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index bf7f24c..35d9f5a 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -620,7 +620,7 @@ class StoreOrderRepository extends BaseRepository $where['uid'] = $uid; } else if (!$uid) { $with['user'] = function ($query) { - return $query->field('uid,nickname'); + return $query->field('uid,nickname,spread_uid'); }; } $order = $this->dao->search($where)->where('order_id', $id)->where('StoreOrder.is_del', 0)->with($with)->append(['refund_status','open_receipt'])->find(); diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index dce7b32..239644a 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -14,6 +14,7 @@ namespace app\common\repositories\user; use app\common\dao\user\UserAssetsLogDao; +use app\common\model\store\StoreOrderHot; use app\common\repositories\BaseRepository; use app\common\repositories\store\order\StoreOrderHotRepository; use app\common\repositories\store\order\StoreOrderRepository; @@ -30,49 +31,52 @@ use think\facade\Log; */ class UserAssetsLogRepository extends BaseRepository { - const ASSET_TYPE_INTEGRAL = 1; // 积分 - const ASSET_TYPE_DIAMOND = 2; // 钻石 - const ASSET_TYPE_STOCK = 3; // 本票 - - const CHANGE_TYPE_RECOMMEND_PRODUCT = 1; // 爆单商品 - const CHANGE_TYPE_SHARE = 2; // 分享奖 - const CHANGE_TYPE_SERVER = 3; // 服务奖 - const CHANGE_TYPE_SAVE = 4; // 预存 - const CHANGE_TYPE_WITHDRAW = 5; // 积分提现 - const CHANGE_TYPE_INTEGRAL_SEND = 6; // 积分转让 - const CHANGE_TYPE_INTEGRAL_GET = 7; // 积分接收 - const CHANGE_TYPE_DIAMOND_SEND = 8; // 钻石转让 - const CHANGE_TYPE_DIAMOND_GET = 9; // 钻石接收 - const CHANGE_TYPE_DIAMOND_LOTTERY = 10; // 抽奖 - const CHANGE_TYPE_DIAMOND = 11; // 兑换钻石 - const CHANGE_TYPE_STOCK = 12; // 兑换本票 - const CHANGE_TYPE_USE = 13; // 消费 + const ASSET_INTEGRAL = 1; // 消费积分积分 + const ASSET_DIAMOND = 2; // 钻石 + const ASSET_STOCK = 3; // 本票 + + const INTEGRAL_WITHDRAW_SHARE = 1; // '分享奖返佣--提现积分', + const INTEGRAL_BUY_SHARE = 2; // '分享奖返佣--复购积分', + const INTEGRAL_WITHDRAW_SERVE = 3; // '服务奖返佣--提现积分', + const INTEGRAL_BUY_SERVE = 4; // '服务奖返佣--复购积分', + const INTEGRAL_WITHDRAW_SEND = 5; // '他人转让--提现积分', + const INTEGRAL_WITHDRAW_GET = 6; // '转让他人--提现积分', + const INTEGRAL_WITHDRAW_DIAMOND = 7; // '兑换钻石--提现积分', + const INTEGRAL_WITHDRAW_HOT = 8; // '爆单奖--提现积分', + const INTEGRAL_BUY_HOT = 9; // '爆单奖--复购积分', + const INTEGRAL_BUY = 10; // '消费--复购积分', + const INTEGRAL_WITHDRAW = 11; // '提现--提现积分', + + const DIAMOND_SEND = 20; //他人转让 + const DIAMOND_GET = 21; //转让他人 + const DIAMOND_STOCK = 22; //兑换本票 + const DIAMOND_INTEGRAL = 23; //积分兑换 + const DIAMOND_SHARE = 24; //分享奖返佣 + const DIAMOND_SERVE = 25; //服务奖返佣 + const DIAMOND_DEPOSIT = 26; //预存奖返佣 + const DIAMOND_LOTTERY = 27; //幸运大转盘奖励 + + const STOCK = 30; //钻石兑换 const STATUS_GET = 1; // 获取 const STATUS_USE = 2; // 使用 const STATUS_WITHDRAW = 3; // 提现 + const STATUS_BUY = 4; // 消费 + const STATUS_REFUND = 5; // 退款 - public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, + public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository, GroupDataRepository $groupRepository, - UserRepository $userRepository + UserRepository $userRepository ) { - $this->dao = $dao; - /** - * @var UserAssetsRepository - */ + $this->dao = $dao; + $this->userAssetsRepository = $userAssetsRepository; - /** - * @var ProductRepository - */ - $this->productRepository = $productRepository; - $this->groupDataRepository = $groupRepository; - /** - * @var UserRepository $userRepository - */ - $this->userRepository = $userRepository; + $this->productRepository = $productRepository; + $this->groupDataRepository = $groupRepository; + $this->userRepository = $userRepository; } /** @@ -86,28 +90,36 @@ class UserAssetsLogRepository extends BaseRepository public function getChangeType() { return array( - self::CHANGE_TYPE_RECOMMEND_PRODUCT => '爆单商品', - self::CHANGE_TYPE_SHARE => '分享奖', - self::CHANGE_TYPE_SERVER => '服务奖', - self::CHANGE_TYPE_SAVE => '预存', - self::CHANGE_TYPE_WITHDRAW => '积分提现', - self::CHANGE_TYPE_INTEGRAL_SEND => '积分转让', - self::CHANGE_TYPE_INTEGRAL_GET => '积分接收', - self::CHANGE_TYPE_DIAMOND_SEND => '钻石转让', - self::CHANGE_TYPE_DIAMOND_GET => '钻石接收', - self::CHANGE_TYPE_DIAMOND_LOTTERY => '抽奖', - self::CHANGE_TYPE_DIAMOND => '兑换钻石', - self::CHANGE_TYPE_STOCK => '兑换本票', - self::CHANGE_TYPE_USE => '消费', + self::INTEGRAL_WITHDRAW_SHARE => '分享奖返佣--提现积分', + self::INTEGRAL_BUY_SHARE => '分享奖返佣--复购积分', + self::INTEGRAL_WITHDRAW_SERVE => '服务奖返佣--提现积分', + self::INTEGRAL_BUY_SERVE => '服务奖返佣--复购积分', + self::INTEGRAL_WITHDRAW_SEND => '他人转让--提现积分', + self::INTEGRAL_WITHDRAW_GET => '转让他人--提现积分', + self::INTEGRAL_WITHDRAW_DIAMOND => '兑换钻石--提现积分', + self::INTEGRAL_WITHDRAW_HOT => '爆单奖--提现积分', + self::INTEGRAL_BUY_HOT => '爆单奖--复购积分', + self::INTEGRAL_BUY => '消费--复购积分', + self::INTEGRAL_WITHDRAW => '提现--提现积分', + + self::DIAMOND_SEND => '他人转让', + self::DIAMOND_GET => '转让他人', + self::DIAMOND_STOCK => '兑换本票', + self::DIAMOND_INTEGRAL => '积分兑换', + self::DIAMOND_SHARE => '分享奖返佣', + self::DIAMOND_SERVE => '服务奖返佣', + self::DIAMOND_DEPOSIT => '预存奖返佣', + self::DIAMOND_LOTTERY => '幸运大转盘奖励', + self::STOCK => '钻石兑换', ); } public function getAssetType() { return array( - self::ASSET_TYPE_INTEGRAL => '积分', - self::ASSET_TYPE_DIAMOND => '钻石', - self::ASSET_TYPE_STOCK => '本票', + self::ASSET_INTEGRAL => '积分', + self::ASSET_DIAMOND => '钻石', + self::ASSET_STOCK => '本票', ); } @@ -143,18 +155,37 @@ class UserAssetsLogRepository extends BaseRepository $order = $orderRepository->getDetail($orderItem['order_id']); + $topUid = 0; + $spreadUid = $order['user']['spread_uid']; + if ($spreadUid) { + $spreadUser = $this->userRepository->get($spreadUid); + $topUid = $spreadUser['spread_uid']; + } + // 爆单奖励 $this->hotAward($order); // 分享奖励 - $this->shareAward($order); + $this->shareAward($order, $spreadUid, $topUid); - $this->serveAward($order); + // 服务奖 + $this->serveAward($order, $spreadUid, $topUid); } - public function serveAward($order){ - + /** + * notes 服务奖计算 + * @param $order + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @create 2024/4/12 9:10 + * @update 2024/4/12 9:10 + * @author zhangkxiang + * @editor + */ + public function serveAward($order, $spreadUid = 0, $topUid = 0) + { /** * @var UserGroupRepository $groupRepository */ @@ -165,40 +196,58 @@ class UserAssetsLogRepository extends BaseRepository foreach ($order['orderProduct'] as $productItem) { $product = $this->productRepository->get($productItem['product_id']); - $profit = $productItem['total_price'] - $productItem['cost']; + $profit = $productItem['total_price'] - $productItem['cost'] * $productItem['product_num']; if ($product['is_hot']) { - $shareRate = $product['hot_integral_one'] + $product['hot_integral_two']; + $shareRate = 0; + if ($spreadUid) { + $shareRate += $product['hot_integral_one']; + } + if ($topUid) { + $shareRate += $product['hot_integral_two']; + } } else { - $shareRate = $product['normal_integral_one'] + $product['normal_integral_two']; + $shareRate = 0; + if ($spreadUid) + $shareRate += $product['normal_integral_one']; + if ($topUid) + $shareRate += $product['normal_integral_two']; } - $total = $this->_getValue($profit - $productItem['total_price'] * (100 - $shareRate)/100); - if($total < 0){ + $total = $this->_getValue($profit - $productItem['total_price'] * $shareRate / 100); + if ($total < 0) { continue; } $currentRate = 0; - foreach ($groupList as $group){ - $where = array('group_id' => $group['group_id']); + foreach ($groupList as $group) { + $where = array('group_id' => $group['group_id']); $userList = $this->userRepository->selectWhere($where); - if($userList->isEmpty()){ + if ($userList->isEmpty()) { continue; } - $integral = $this->_getValue($total*($group['rate'] - $currentRate)/100/count($userList)); - var_dump(array($profit, $total, $integral)); + $tmp = $this->_getIntegral($total * ($group['rate'] - $currentRate) / 100 / count($userList)); $logList = array(); - foreach ($userList as $user){ + foreach ($userList as $user) { + $logList[] = array( + 'uid' => $user['uid'], + 'asset_type' => self::ASSET_INTEGRAL, + 'type' => self::INTEGRAL_WITHDRAW_SERVE, + 'status' => self::STATUS_GET, + 'product_id' => $productItem['product_id'], + 'order_id' => $order['order_id'], + 'count' => $tmp['integral_withdraw'], + ); $logList[] = array( 'uid' => $user['uid'], - 'asset_type' => self::ASSET_TYPE_INTEGRAL, - 'type' => self::CHANGE_TYPE_SERVER, + 'asset_type' => self::ASSET_INTEGRAL, + 'type' => self::INTEGRAL_BUY_SERVE, 'status' => self::STATUS_GET, 'product_id' => $productItem['product_id'], 'order_id' => $order['order_id'], - 'count' => $integral, + 'count' => $tmp['integral_buy'], ); - $this->userAssetsRepository->updateAssets($user['uid'], array('integral' => $integral)); + $this->userAssetsRepository->updateAssets($user['uid'], $tmp); } $this->addLog($logList); $currentRate = $group['rate']; @@ -206,11 +255,13 @@ class UserAssetsLogRepository extends BaseRepository } } + // 最后计算用户等级 $this->_updateUserGroup($order['uid']); } - private function _updateUserGroup($orderUid){ + private function _updateUserGroup($orderUid) + { /** * @var UserGroupRepository $groupRepository */ @@ -224,26 +275,26 @@ class UserAssetsLogRepository extends BaseRepository $groupData = $groupRepository->getList([], 1, 10); $groupList = array_reverse($groupData['list']->toArray()); - $user= $this->userRepository->get($orderUid); + $user = $this->userRepository->get($orderUid); $count = 0; - while ($user){ - $uidArr = $this->getAllSpreadId($user['uid']); - $uidArr = array_merge($uidArr, [$user['uid']]); + while ($user) { + $uidArr = $this->getAllSpreadId($user['uid']); + $uidArr = array_merge($uidArr, [$user['uid']]); $orderData = $orderRepository->orderStatisticsByUidArr($uidArr); - foreach ($groupList as $group){ - if($orderData['count'] >= $group['order_count'] or $orderData['sum'] >= $group['order_sum']){ + foreach ($groupList as $group) { + if ($orderData['count'] >= $group['order_count'] or $orderData['sum'] >= $group['order_sum']) { $user['group_id'] = $group['group_id']; $user->save(); break; } } - if($user['spread_uid']){ + if ($user['spread_uid']) { $user = $this->userRepository->get($user['spread_uid']); - }else{ + } else { break; } $count++; - if($count>=20){ + if ($count >= 20) { break; } } @@ -257,58 +308,67 @@ class UserAssetsLogRepository extends BaseRepository * @throws DbException * @throws ModelNotFoundException */ - public function hotAward($order){ + public function hotAward($order) + { /** * @var StoreOrderHotRepository $hotRepository */ $hotRepository = app(StoreOrderHotRepository::class); - foreach ($order['orderProduct'] as $productItem){ + foreach ($order['orderProduct'] as $productItem) { $product = $this->productRepository->get($productItem['product_id']); - Log::info("product is". json_encode($product)); - if(empty($product['is_hot'])){ + if (empty($product['is_hot']) or empty($product['hot_integral_rate'])) { continue; } $item = $hotRepository->getWhere(['product_id' => $productItem['product_id'], 'uid' => $order['uid']]); - if($item){ + if ($item) { $item['total'] += $product['hot_integral_total'] * $productItem['product_num']; - }else{ + $item->save(); + } else { // 先创建一条记录 $hotData = array( - 'uid' => $order['uid'], - 'product_id' => $productItem['product_id'], - 'total' => $product['hot_integral_total'] * $productItem['product_num'], + 'uid' => $order['uid'], + 'product_id' => $productItem['product_id'], + 'total' => $product['hot_integral_total'] * $productItem['product_num'], 'create_time' => date('Y-m-d H:i:s') ); $hotRepository->create($hotData); } // 计算每个购买当前爆单商品的积分数据 - $profit = $productItem['total_price'] - $productItem['cost']; - $where = array(); + $profit = $productItem['total_price'] - $productItem['cost']*$productItem['product_num']; + $where = array(); $where[] = array('product_id', '=', $productItem['product_id']); - $where[] = array('total', '>', 'current'); - $list = $hotRepository->getList($where); + $list = $hotRepository->getList($where); $logList = array(); - foreach ($list as $item){ - $tmp = array('integral' => $this->_getValue($profit * $product['hot_integral_rate'] / 100 / count($list))); - if($item['total'] - $item['current'] < $tmp['integral']){ - $tmp['integral'] = $item['total'] - $item['current']; + foreach ($list as $item) { + $tmp = $this->_getIntegral($profit * $product['hot_integral_rate'] / 100 / count($list)); + if ($item['total'] - $item['current'] < $tmp['integral_buy'] + $tmp['integral_withdraw']) { + $tmp = $this->_getIntegral($item['total'] - $item['current']); $item['status'] = 1; } $this->userAssetsRepository->updateAssets($item['uid'], $tmp); - $item['current'] += $tmp['integral']; + $item['current'] += $tmp['integral_buy'] + $tmp['integral_withdraw']; $item->save(); $logList[] = array( 'uid' => $item['uid'], - 'asset_type' => self::ASSET_TYPE_INTEGRAL, - 'type' => self::CHANGE_TYPE_RECOMMEND_PRODUCT, + 'asset_type' => self::ASSET_INTEGRAL, + 'type' => self::INTEGRAL_BUY_HOT, 'status' => self::STATUS_GET, 'product_id' => $productItem['product_id'], 'order_id' => $order['order_id'], - 'count' => $tmp['integral'], + 'count' => $tmp['integral_buy'], + ); + $logList[] = array( + 'uid' => $item['uid'], + 'asset_type' => self::ASSET_INTEGRAL, + 'type' => self::INTEGRAL_WITHDRAW_HOT, + 'status' => self::STATUS_GET, + 'product_id' => $productItem['product_id'], + 'order_id' => $order['order_id'], + 'count' => $tmp['integral_withdraw'], ); } $this->addLog($logList); @@ -323,13 +383,12 @@ class UserAssetsLogRepository extends BaseRepository * @author zhangkxiang * @editor */ - public function shareAward($order) + public function shareAward($order, $spreadUid = 0, $topUid = 0) { - $LogList = array(); foreach ($order['orderProduct'] as $productItem) { $product = $this->productRepository->get($productItem['product_id']); // 取当前商品的总价 - $profit = $productItem['total_price']; + $profit = $productItem['total_price']; if ($product['is_hot']) { $integralOne = $product['hot_integral_one']; @@ -342,67 +401,68 @@ class UserAssetsLogRepository extends BaseRepository $diamondOne = $product['normal_diamond_one']; $diamondTwo = $product['normal_diamond_two']; } - if ($order['spread_uid']) { - $tmp = array('diamond' => $diamondOne, 'integral' => $this->_getValue($profit * $integralOne / 100)); - $LogList[] = array( - 'uid' => $order['spread_uid'], - 'asset_type' => self::ASSET_TYPE_INTEGRAL, - 'type' => self::CHANGE_TYPE_SHARE, - 'status' => self::STATUS_GET, - 'product_id' => $productItem['product_id'], - 'order_id' => $order['order_id'], - 'count' => $tmp['integral'], - ); - $LogList[] = array( - 'uid' => $order['spread_uid'], - 'asset_type' => self::ASSET_TYPE_DIAMOND, - 'type' => self::CHANGE_TYPE_SHARE, - 'status' => self::STATUS_GET, - 'product_id' => $productItem['product_id'], - 'order_id' => $order['order_id'], - 'count' => $diamondOne, - ); - $this->userAssetsRepository->updateAssets($order['spread_uid'], $tmp); - } - if ($order['top_uid']) { - $tmp = array('diamond' => $diamondTwo, 'integral' => $this->_getValue($profit * $integralTwo / 100)); - $LogList[] = array( - 'uid' => $order['top_uid'], - 'asset_type' => self::ASSET_TYPE_INTEGRAL, - 'type' => self::CHANGE_TYPE_SHARE, - 'status' => self::STATUS_GET, - 'product_id' => $productItem['product_id'], - 'order_id' => $order['order_id'], - 'count' => $tmp['integral'], - ); - $LogList[] = array( - 'uid' => $order['top_uid'], - 'asset_type' => self::ASSET_TYPE_DIAMOND, - 'type' => self::CHANGE_TYPE_SHARE, - 'status' => self::STATUS_GET, - 'product_id' => $productItem['product_id'], - 'order_id' => $order['order_id'], - 'count' => $diamondTwo, - ); - $this->userAssetsRepository->updateAssets($order['top_uid'], $tmp); - } + + $this->_shareInsertData($spreadUid, $integralOne, $diamondOne, $profit, $productItem['product_id'], $order['order_id']); + + $this->_shareInsertData($topUid, $integralTwo, $diamondTwo, $profit, $productItem['product_id'], $order['order_id']); + + } + } + + + private function _shareInsertData($uid, $integral, $diamond, $profit, $productId, $orderId) + { + if (empty($uid)) { + return; } - $this->addLog($LogList); + $logList = array(); + $tmp = $this->_getIntegral($profit * $integral / 100); + $tmp['diamond'] = $diamond; + $logList[] = array( + 'uid' => $uid, + 'asset_type' => self::ASSET_INTEGRAL, + 'type' => self::INTEGRAL_BUY_SHARE, + 'status' => self::STATUS_GET, + 'product_id' => $productId, + 'order_id' => $orderId, + 'count' => $tmp['integral_buy'], + ); + $logList[] = array( + 'uid' => $uid, + 'asset_type' => self::ASSET_INTEGRAL, + 'type' => self::INTEGRAL_WITHDRAW_SHARE, + 'status' => self::STATUS_GET, + 'product_id' => $productId, + 'order_id' => $orderId, + 'count' => $tmp['integral_withdraw'], + ); + $logList[] = array( + 'uid' => $uid, + 'asset_type' => self::ASSET_DIAMOND, + 'type' => self::DIAMOND_SHARE, + 'status' => self::STATUS_GET, + 'product_id' => $productId, + 'order_id' => $orderId, + 'count' => $diamond, + ); + $this->userAssetsRepository->updateAssets($uid, $tmp); + $this->addLog($logList); } - public function getAllSpreadId($uid, $count= 0){ - if($count>=30){ + public function getAllSpreadId($uid, $count = 0) + { + if ($count >= 30) { return array(); } $key = "user:AllSpread1:{$uid}"; $ret = Cache::get($key); - if($ret === null){ - $uidArr = $this->userRepository->getSubIds($uid); + if ($ret === null) { + $uidArr = $this->userRepository->getSubIds($uid); $childArr = array(); - if($uidArr){ - foreach ($uidArr as $itemUid){ + if ($uidArr) { + foreach ($uidArr as $itemUid) { $childArr = array_merge($this->getAllSpreadId($itemUid, ++$count), $childArr); } } @@ -419,6 +479,14 @@ class UserAssetsLogRepository extends BaseRepository } + public function _getIntegral($total) + { + $integral_buy = round($total * 0.2, 2); + $integral_withdraw = $total - $integral_buy; + return array('integral_buy' => $integral_buy, 'integral_withdraw' => $integral_withdraw); + } + + /** * notes 插入变动日志,如果小于0.01则插入0.01 * @param $list @@ -429,10 +497,14 @@ class UserAssetsLogRepository extends BaseRepository */ public function addLog($list) { + $addData = array(); foreach ($list as $key => $item) { - $list[$key]['ext'] = $item['ext'] ?? array(); + $item['ext'] = $item['ext'] ?? array(); + if ($item['count']) { + $addData[] = $item; + } } - $this->dao->insertAll($list); + $this->dao->insertAll($addData); } diff --git a/app/common/repositories/user/UserAssetsRepository.php b/app/common/repositories/user/UserAssetsRepository.php index 6e61c5d..f3c9b78 100644 --- a/app/common/repositories/user/UserAssetsRepository.php +++ b/app/common/repositories/user/UserAssetsRepository.php @@ -83,10 +83,12 @@ class UserAssetsRepository extends BaseRepository { $assets = $this->assets($uid); $update = array('integral_buy' => 0, 'integral_withdraw' => 0, 'diamond' => 0, 'stock' => 0); - if (isset($data['integral']) and $data['integral']) { - $tmp = $this->getIntegral($data['integral']); - $update['integral_buy'] = $tmp['integral_buy']; - $update['integral_withdraw'] = $tmp['integral_withdraw']; + + if (isset($data['integral_buy']) and $data['integral_buy']) { + $update['integral_buy'] = $data['integral_buy']; + } + if (isset($data['integral_withdraw']) and $data['integral_withdraw']) { + $update['integral_withdraw'] = $data['integral_withdraw']; } if (isset($data['diamond']) and $data['diamond']) { $update['diamond'] = $data['diamond']; @@ -104,12 +106,6 @@ class UserAssetsRepository extends BaseRepository $this->dao->update($uid, $updateData); } - public function getIntegral($total) - { - $integral_buy = round($total * 0.2, 2); - $integral_withdraw = round($total * 0.8, 2); - return array('integral_buy' => $integral_buy, 'integral_withdraw' => $integral_withdraw); - } /** @@ -136,15 +132,15 @@ class UserAssetsRepository extends BaseRepository $integralCount = -1 * $config['integralToDiamond'] * $count; $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND, + 'asset_type' => UserAssetsLogRepository::ASSET_INTEGRAL, + 'type' => UserAssetsLogRepository::INTEGRAL_WITHDRAW_DIAMOND, 'status' => UserAssetsLogRepository::STATUS_USE, 'count' => $integralCount, ); $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND, + 'asset_type' => UserAssetsLogRepository::ASSET_DIAMOND, + 'type' => UserAssetsLogRepository::DIAMOND_INTEGRAL, 'status' => UserAssetsLogRepository::STATUS_GET, 'count' => $count, ); @@ -175,16 +171,16 @@ class UserAssetsRepository extends BaseRepository $diamond = -1 * $config['diamondToStock'] * $count; $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_STOCK, + 'asset_type' => UserAssetsLogRepository::ASSET_DIAMOND, + 'type' => UserAssetsLogRepository::DIAMOND_DEPOSIT, 'status' => UserAssetsLogRepository::STATUS_USE, 'count' => $diamond, ); $stock = $count; $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_STOCK, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_STOCK, + 'asset_type' => UserAssetsLogRepository::ASSET_STOCK, + 'type' => UserAssetsLogRepository::STOCK, 'status' => UserAssetsLogRepository::STATUS_GET, 'count' => $stock, ); @@ -229,8 +225,8 @@ class UserAssetsRepository extends BaseRepository $logList[] = array( 'uid' => $toUser['uid'], - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_INTEGRAL_GET, + 'asset_type' => UserAssetsLogRepository::ASSET_INTEGRAL, + 'type' => UserAssetsLogRepository::INTEGRAL_WITHDRAW_GET, 'status' => UserAssetsLogRepository::STATUS_GET, 'count' => $count - $rate, 'fee' => 0, @@ -241,8 +237,8 @@ class UserAssetsRepository extends BaseRepository ); $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_INTEGRAL_SEND, + 'asset_type' => UserAssetsLogRepository::ASSET_INTEGRAL, + 'type' => UserAssetsLogRepository::INTEGRAL_WITHDRAW_SEND, 'status' => UserAssetsLogRepository::STATUS_USE, 'count' => -1 * $count, 'fee' => $rate, @@ -276,7 +272,7 @@ class UserAssetsRepository extends BaseRepository $config = $this->getConfig(); $assets = $this->assets($uid); if ($assets['diamond'] < $count) { - throw new \Exception('积分不足'); + throw new \Exception('钻石不足'); } /** * @var UserRepository $userRepository @@ -293,8 +289,8 @@ class UserAssetsRepository extends BaseRepository $logList[] = array( 'uid' => $toUser['uid'], - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND_GET, + 'asset_type' => UserAssetsLogRepository::ASSET_DIAMOND, + 'type' => UserAssetsLogRepository::DIAMOND_GET, 'status' => UserAssetsLogRepository::STATUS_GET, 'count' => $count - $rate, 'fee' => 0, @@ -305,8 +301,8 @@ class UserAssetsRepository extends BaseRepository ); $logList[] = array( 'uid' => $uid, - 'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, - 'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND_SEND, + 'asset_type' => UserAssetsLogRepository::ASSET_DIAMOND, + 'type' => UserAssetsLogRepository::DIAMOND_SEND, 'status' => UserAssetsLogRepository::STATUS_USE, 'count' => -1 * $count, 'fee' => $rate, diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 7e17155..6676086 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -78,7 +78,7 @@ class Auth extends BaseController // } // app(UserAssetsLogRepository::class)->shareAward(1); - event('order.take', array('order' => array('order_id' => 1))); + event('order.take', array('order' => array('order_id' => 3))); return app('json')->success(); } diff --git a/app/controller/api/store/product/StoreProduct.php b/app/controller/api/store/product/StoreProduct.php index eafa903..00ab539 100755 --- a/app/controller/api/store/product/StoreProduct.php +++ b/app/controller/api/store/product/StoreProduct.php @@ -127,7 +127,7 @@ class StoreProduct extends BaseController $url = $this->repository->wxQrCode($id, $param['product_type'], $this->request->userInfo()); } - if (!$url) return app('json')->fail('二维码生成失败'); +// if (!$url) return app('json')->fail('二维码生成失败'); return app('json')->success(compact('url')); }