12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- /**
- * Created by PhpStorm.
- * User: edz
- * Date: 2019-06-10
- * Time: 17:53
- */
- namespace App\Repositories;
- use App\Models\Behavior;
- use Illuminate\Support\Facades\Log;
- class BehaviorRepositories
- {
- public function __construct(MemberRepository $memberRepository)
- {
- $this->memberRepository = $memberRepository;
- }
- /**
- * 消费virus通知
- * @param array $request
- */
- public function consumeNotify($request)
- {
- $identify = $request['behavior_flag'];
- $behavior = $this->getBehavior($identify);
- $userInfo = $this->memberRepository->getUserInfo();
- if (empty($userInfo) || empty($behavior)) {
- return true;
- }
- $behaviorStatus = 0; //触发类型
- if ($userInfo && $userInfo['strength'] > 0) {
- $behaviorStatus = 1;
- }
- $strength = $behaviorStatus ? $behavior['physical_strength'] : 0;
- $beans = $behaviorStatus ? $behavior['rainbow_beans'] : 0;
- }
- /**
- * 获取行为绑定规则
- * @param $info
- * @return array
- */
- public function getBehavior($identify)
- {
- $info = Behavior::where([['is_open', '=', 1], ['behavior_identification', '=', $identify]])->first();
- Log::debug('behavior:' . json_encode($info));
- if ($info) {
- return $info;
- }
- return [];
- }
- }
|