|
|
@@ -19,12 +19,14 @@ use app\models\user\User;
|
|
|
use app\models\user\UserBill;
|
|
|
use app\models\user\WechatUser;
|
|
|
use app\Request;
|
|
|
+use crmeb\basic\BaseModel;
|
|
|
use crmeb\services\CacheService;
|
|
|
use crmeb\services\UtilService;
|
|
|
use crmeb\services\workerman\ChannelService;
|
|
|
use think\db\exception\DataNotFoundException;
|
|
|
use think\db\exception\DbException;
|
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
+use think\Exception;
|
|
|
use think\facade\Cache;
|
|
|
use crmeb\services\upload\Upload;
|
|
|
|
|
|
@@ -36,9 +38,56 @@ use crmeb\services\upload\Upload;
|
|
|
class PublicController
|
|
|
{
|
|
|
|
|
|
- public function test()
|
|
|
+ public function test(Request $request)
|
|
|
{
|
|
|
- $resPink = StorePink::createPink(StoreOrder::get(6));
|
|
|
+ BaseModel::beginTrans();
|
|
|
+ try {
|
|
|
+ $uid = $request->post('uid');
|
|
|
+ $res = TreeRecommend::insertTree($uid, User::where('uid', $uid)->value('spread_uid'));
|
|
|
+ $res = $res && self::pinkIntegral($uid);
|
|
|
+ $res = $res && self::pinkRecommend($uid);
|
|
|
+ if ($res) {
|
|
|
+ return app('json')->success('成功');
|
|
|
+ } else {
|
|
|
+ return app('json')->fail('失败');
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ BaseModel::rollbackTrans();
|
|
|
+ return app('json')->fail($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function pinkIntegral($uid)
|
|
|
+ {
|
|
|
+ $return = 3000;
|
|
|
+ $res = true;
|
|
|
+ if ($return > 0) {
|
|
|
+ $balance = User::where('uid', $uid)->value('integral');
|
|
|
+ $res = $res && UserBill::income('拼团中奖送响亮积分', $uid, 'integral', 'pink_success', $return, 0, $balance + $return, '参加拼团中奖,获得响亮积分' . $return);
|
|
|
+ $res = $res && User::where('uid', $uid)->inc('integral', $return)->update();
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function pinkRecommend($uid)
|
|
|
+ {
|
|
|
+ $user = User::where('uid', $uid)->find();
|
|
|
+ $spread = User::where('uid', $user['spread_uid'])->find();
|
|
|
+ if (!$spread) return true;
|
|
|
+ if ($spread['last_recommend_award']) $return = sys_config('recommend_double', 0);
|
|
|
+ else $return = sys_config('recommend_single', 0);
|
|
|
+ if ($spread['integral'] < $return) return true;
|
|
|
+ $res = true;
|
|
|
+ if ($return > 0) {
|
|
|
+ $balance_integral = User::where('uid', $spread['uid'])->value('integral');
|
|
|
+ $balance_brokerage = User::where('uid', $spread['uid'])->value('brokerage_price');
|
|
|
+ $res = $res && UserBill::expend('推荐拼团奖[积分转换]', $spread['uid'], 'integral', 'pink_recommend_pay', $return, 0, bcsub($balance_integral, $return, 2), '推荐用户拼团,响亮积分转为推荐奖' . $return);
|
|
|
+ $res = $res && UserBill::income('推荐拼团奖', $spread['uid'], 'brokerage_price', 'pink_recommend_income', $return, 0, bcadd($balance_brokerage, $return, 2), '推荐用户拼团,响亮积分转为推荐奖' . $return);
|
|
|
+ $res = $res && User::where('uid', $spread['uid'])->dec('integral', $return)->update();
|
|
|
+ $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $return)->update();
|
|
|
+ $res = $res && User::where('uid', $spread['uid'])->update(['last_recommend_award' => ($spread['last_recommend_award'] ? 0 : 1)]);
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
}
|
|
|
|
|
|
/**
|