LevelUp.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <?php
  2. namespace addons\CloudStockTwo\common\logic\level_up;
  3. use addons\CloudStockTwo\common\enums\CloudStockTwoEnum;
  4. use addons\CloudStockTwo\common\logic\order\FillOrderLogic;
  5. use addons\CloudStockTwo\common\models\CloudStockTwoAgent;
  6. use addons\CloudStockTwo\common\models\CloudStockTwoAgentGoods;
  7. use addons\CloudStockTwo\common\models\CloudStockTwoAgentQuota;
  8. use addons\CloudStockTwo\common\models\CloudStockTwoFillOrder;
  9. use addons\CloudStockTwo\common\models\CloudStockTwoLevel;
  10. use addons\CloudStockTwo\common\models\CloudStockTwoUpgradeBag;
  11. use addons\CloudStockTwo\common\sms\LevelUpgradeMessage;
  12. use addons\CloudStockTwo\common\sms\SmsConfig;
  13. use addons\CloudStockTwo\common\logic\reward\LevelRewardLogic;
  14. use common\enums\AddonsEnum;
  15. use common\enums\StatusEnum;
  16. use common\helpers\FormatHelper;
  17. use common\helpers\sms\Sms;
  18. use common\helpers\StringHelper;
  19. use common\models\order\OrderDetail;
  20. use common\models\user\User;
  21. use common\models\user\UserPartitionRelationship;
  22. use Overtrue\EasySms\EasySms;
  23. use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
  24. use yii\db\Exception;
  25. class LevelUp
  26. {
  27. public static $reward_unit_price = 0;
  28. public static function handle($mall_id, $user_id, $goods_id_arr, $order_id,$order_type)
  29. {
  30. $t = \Yii::$app->db->beginTransaction();
  31. try {
  32. $configs = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_CLOUD_STOCK_TWO, 'basic');
  33. if (empty($configs['is_enable'])) throw new Exception('没开启云库存');
  34. $upgrade_bag_list = CloudStockTwoUpgradeBag::lists(['where' => [['mall_id' => $mall_id], ['goods_id' => $goods_id_arr], ['status' => StatusEnum::ENABLED]], 'order' => 'level asc']);
  35. $cloud_stock_agent = CloudStockTwoAgent::findOne(['user_id' => $user_id, 'status' => StatusEnum::ENABLED]);
  36. if (empty($cloud_stock_agent)) {
  37. $cloud_stock_agent = new CloudStockTwoAgent();
  38. $cloud_stock_agent->user_id = $user_id;
  39. $cloud_stock_agent->mall_id = $mall_id;
  40. }
  41. $before_level = $cloud_stock_agent->level ?? 0;
  42. //购买升级礼包升级
  43. $time = time();
  44. if (!empty($upgrade_bag_list)) {
  45. $level_up_give_stock_by_parent = $configs['level_up_give_stock_by_parent'] ?? 0;
  46. self::upgradeBagUp($mall_id, $user_id, $order_id, $upgrade_bag_list, $cloud_stock_agent, $time, $before_level, $level_up_give_stock_by_parent,$order_type);
  47. }
  48. $level = 0;
  49. if (!empty($cloud_stock_agent->level)) $level = $cloud_stock_agent->level;
  50. $level_list = CloudStockTwoLevel::lists(['where' => [
  51. ['mall_id' => $mall_id],
  52. ['>', 'level', $level],
  53. ['status' => StatusEnum::ENABLED]
  54. ], 'order' => 'level desc'
  55. ]);
  56. //购买商品升级
  57. if (!empty($level_list)) {
  58. self::conditionUp($user_id, $goods_id_arr, $cloud_stock_agent, $time, $before_level, $level_list,$order_id,$order_type);
  59. }
  60. $t->commit();
  61. //触发升级上级代理商是否满足升级
  62. $parent_agent_list = self::getUserParentAgentList($mall_id,$user_id);
  63. foreach ($parent_agent_list as $agent) {
  64. $level = 0;
  65. if (!empty($agent->level)) $level = $agent['level'];
  66. $level_list = CloudStockTwoLevel::lists(['where' => [
  67. ['mall_id' => $mall_id],
  68. ['>', 'level', $level],
  69. ['status' => StatusEnum::ENABLED]
  70. ], 'order' => 'level desc'
  71. ]);
  72. self::conditionUp($agent['user_id'], [], $agent, $time, $agent['before_level'], $level_list,$order_id,$order_type);
  73. }
  74. return true;
  75. } catch (\Exception $e) {
  76. $t->rollBack();
  77. $exception = FormatHelper::exception($e, $e->getMessage() . $e->getFile() . $e->getLine());
  78. //echo $exception;
  79. \Yii::error($exception);
  80. return false;
  81. }
  82. }
  83. public static function getUserParentAgentList($mall_id,$agent_user_id)
  84. {
  85. $parent_id_arr = UserPartitionRelationship::getParentIdArr($agent_user_id);
  86. $parent_id_arr = array_reverse($parent_id_arr);
  87. $parent_agent_list = CloudStockTwoAgent::lists(['where' => [['user_id' => $parent_id_arr],['status'=>StatusEnum::ENABLED]], 'index' => 'user_id'], false);
  88. $list = [];
  89. foreach ($parent_id_arr as $user_id) {
  90. if (isset($parent_agent_list[$user_id])) {
  91. $list[] = $parent_agent_list[$user_id];
  92. }else{
  93. $model = new CloudStockTwoAgent();
  94. $model->loadDefaultValues();
  95. $model->mall_id = $mall_id;
  96. $model->user_id = $user_id;
  97. $model->level = 0;
  98. $model->before_level = 0;
  99. $list[] = $model;
  100. }
  101. }
  102. return $list;
  103. }
  104. public static function upgradeBagUp($mall_id, $user_id, $order_id, $upgrade_bag_list, $cloud_stock_agent, $time, $before_level, $level_up_give_stock_by_parent,$order_type)
  105. {
  106. $level = 0;
  107. $give_arr = [];
  108. foreach ($upgrade_bag_list as $item) {
  109. $level = $item['level'];
  110. // if (!empty($item['give_goods_id'])) {
  111. // $give_arr[$item['give_goods_id']] = $item['give_goods_num'];
  112. // }
  113. if (!empty($item['give_goods_info'])) {
  114. $item['give_goods_info'] = json_decode($item['give_goods_info'],true) ?? [];
  115. foreach($item['give_goods_info'] as $info){
  116. if(!empty($info['num'])){
  117. $give_arr[$info['goods_id']] = $info['num'];
  118. }
  119. }
  120. }
  121. }
  122. $cloud_stock_level_model = CloudStockTwoLevel::findOne(['mall_id' => $mall_id, 'level' => $level, 'status' => StatusEnum::ENABLED]);
  123. if (empty($cloud_stock_level_model)) return false;
  124. if ($cloud_stock_agent->level >= $level) return true;
  125. $cloud_stock_agent->level = $level;
  126. $cloud_stock_agent->upgrade_status = CloudStockTwoEnum::UPGRADE_STATUS_GOODS;
  127. $cloud_stock_agent->upgrade_at = $time;
  128. $cloud_stock_agent->before_level = $before_level;
  129. $res = $cloud_stock_agent->save();
  130. if ($res) {
  131. self::updateQuota($cloud_stock_agent);
  132. self::sendMessage($mall_id, $cloud_stock_level_model['name'], $cloud_stock_agent['user_id']);
  133. //触发直推上级奖励
  134. //支付金额
  135. if($order_type == 'fill'){
  136. $order = CloudStockTwoFillOrder::findOne(['id'=>$order_id]);
  137. $price = $order->pay_money ?? 0;
  138. }else{
  139. $order = OrderDetail::findOne(['order_id'=>$order_id]);
  140. $price = $order->goods_price;
  141. $goods_id = $order->goods_id;
  142. }
  143. if($order){
  144. $LevelRewardLogicObj = new LevelRewardLogic($mall_id,$cloud_stock_agent,$order_type,$order_id,$cloud_stock_level_model['name'],$price,$order->goods_id,$order->num);
  145. $LevelRewardLogicObj->addRewardLog();
  146. //返回直推奖励
  147. self::$reward_unit_price += $LevelRewardLogicObj->reward_unit_price;
  148. }
  149. }
  150. //赠送库存
  151. foreach ($give_arr as $goods_id => $num) {
  152. if (!empty($level_up_give_stock_by_parent)) {
  153. //走补货的逻辑
  154. $order_no = StringHelper::generateOrderNo('CSFL');
  155. $params = [
  156. 'user_id' => $user_id,
  157. 'pay_money' => 0,
  158. 'order_no' => $order_no,
  159. 'is_pay' => CloudStockTwoEnum::FILL_STATUS_PAY,
  160. 'goods_id' => $goods_id,
  161. 'num' => $num,
  162. ];
  163. $order = CloudStockTwoFillOrder::setData($mall_id, $params);
  164. if ($order) {
  165. $obj = new FillOrderLogic();
  166. $obj->handle($order);
  167. }
  168. } else {
  169. //最初的方案
  170. //生成代理商商品库存
  171. $params = [
  172. 'mall_id' => $mall_id,
  173. 'user_id' => $user_id,
  174. 'goods_id' => $goods_id,
  175. 'num' => $num,
  176. 'order_id' => $order_id,
  177. 'changes_type' => CloudStockTwoEnum::STOCK_CHANGE_TYPE105,
  178. 'changes_dir' => CloudStockTwoEnum::STOCK_CHANGE_ADD,
  179. 'order_type' => CloudStockTwoEnum::STOCK_ORDER_TYPE_USER,
  180. ];
  181. $res = CloudStockTwoAgentGoods::addData($params);
  182. if (!$res) throw new \Exception(CloudStockTwoAgentGoods::getStaticError());
  183. }
  184. }
  185. }
  186. public static function conditionUp($user_id, $goods_id_arr, $cloud_stock_agent, $time, $before_level, $level_list,$order_id,$order_type)
  187. {
  188. $can_to_level = 0;
  189. $type = 1;
  190. $is_can_up = false;
  191. $mall_id = 0;
  192. $params['user_id'] = $user_id;
  193. $params['goods_id_arr'] = $goods_id_arr;
  194. $params['order_type'] = $order_type;
  195. $params['order_id'] = $order_id;
  196. $is_can_up = false;
  197. $level_name = '';
  198. foreach ($level_list as $level_item) {
  199. $can_to_level = $level_item['level'];
  200. $level_name = $level_item['name'];
  201. $mall_id = $level_item['mall_id'];
  202. if (empty($level_item['upgrade_type_condition'])) continue;
  203. if (!empty($level_item['condition_type'])) {
  204. $condition_type = $level_item['condition_type'];
  205. $checked_condition_values = json_decode($level_item['checked_condition_values'], true);
  206. $checked_condition_keys = json_decode($level_item['checked_condition_keys'], true);
  207. foreach ($checked_condition_keys as $key) {
  208. $method = 'condition' . $key;
  209. $is_bool = self::$method($checked_condition_values, $key, $params);
  210. //满足其一
  211. if ($condition_type == 1) {
  212. if ($is_bool) {
  213. $is_can_up = true;
  214. break;
  215. } else {
  216. $is_can_up = false;
  217. }
  218. }
  219. //满足所有
  220. if ($condition_type == 2) {
  221. if ($is_bool) {
  222. $is_can_up = true;
  223. } else {
  224. $is_can_up = false;
  225. break;
  226. }
  227. }
  228. }
  229. if($is_can_up) break;
  230. }
  231. }
  232. if ($is_can_up && $can_to_level > $cloud_stock_agent->level) {
  233. $cloud_stock_agent->level = $can_to_level;
  234. $cloud_stock_agent->upgrade_status = CloudStockTwoEnum::UPGRADE_STATUS_CONDITION;
  235. $cloud_stock_agent->upgrade_at = $time;
  236. $cloud_stock_agent->before_level = $before_level;
  237. $res = $cloud_stock_agent->save();
  238. if ($res) {
  239. self::updateQuota($cloud_stock_agent);
  240. self::sendMessage($mall_id, $level_name, $cloud_stock_agent['user_id']);
  241. //触发直推上级奖励
  242. //支付金额
  243. if($order_type == 'fill'){
  244. $order = CloudStockTwoFillOrder::findOne(['id'=>$order_id]);
  245. $price = $order->pay_money ?? 0;
  246. }else{
  247. $order = OrderDetail::findOne(['order_id'=>$order_id]);
  248. $price = $order->goods_price;
  249. $goods_id = $order->goods_id;
  250. }
  251. if($order){
  252. $LevelRewardLogicObj = new LevelRewardLogic($mall_id,$cloud_stock_agent,$order_type,$order_id,$level_name,$price,$order->goods_id,$order->num);
  253. $LevelRewardLogicObj->addRewardLog();
  254. //返回直推奖励
  255. self::$reward_unit_price += $LevelRewardLogicObj->reward_unit_price;
  256. }
  257. }
  258. }
  259. }
  260. public static function updateQuota($cloud_stock_agent)
  261. {
  262. $level = CloudStockTwoLevel::findOne(['mall_id' => $cloud_stock_agent['mall_id'], 'level' => $cloud_stock_agent['level'], 'status' => [StatusEnum::ENABLED]]);
  263. if (!empty($level)) {
  264. $give_quota = json_decode($level['give_quota'], true);
  265. foreach ($give_quota as $item) {
  266. if (!empty($item['is_use']) && !empty($item['num'])) {
  267. $params = [];
  268. $params['mall_id'] = $cloud_stock_agent['mall_id'];
  269. $params['user_id'] = $cloud_stock_agent['user_id'];
  270. $params['num'] = $item['num'];
  271. $params['level'] = $item['level'];
  272. $res = CloudStockTwoAgentQuota::setData($params);
  273. if ($res == false) throw new Exception(CloudStockTwoAgentQuota::getStaticError());
  274. }
  275. }
  276. }
  277. }
  278. public static function sendMessage($mall_id, $level_name, $user_id)
  279. {
  280. try {
  281. $SmsConfig = new Sms($mall_id);
  282. $easy_sms = $SmsConfig->easySms;
  283. $message = new LevelUpgradeMessage($mall_id, $level_name);
  284. $user = User::findOne(['id' => $user_id]);
  285. $easy_sms->send($user['mobile'], $message);
  286. } catch (NoGatewayAvailableException $e) {
  287. $res = $e->getExceptions();
  288. if (!empty($res)) {
  289. foreach ($res as $exception) {
  290. if (is_string($exception->getMessage())) {
  291. \Yii::error('云库存升级短信发送失败:' . $exception->getMessage());
  292. }
  293. }
  294. }
  295. } catch (\Exception $e) {
  296. \Yii::error('云库存升级短信发送失败:' . $e->getMessage());
  297. }
  298. }
  299. protected static function condition0($checked_condition_values, $key, $params)
  300. {
  301. //购买指定商品
  302. $upgrade = false;
  303. //取出等级升级商品id
  304. $value_goods_ids = [];
  305. if (isset($checked_condition_values[$key]['value'])) $value_goods_ids = array_column($checked_condition_values[$key]['value'], 'goods_id');
  306. if (empty($value_goods_ids)) $upgrade = false;
  307. $goods_id_arr = $params['goods_id_arr'];
  308. foreach ($goods_id_arr as $goods_id) {
  309. if (in_array($goods_id, $value_goods_ids)) {
  310. if($params['order_type'] == 'fill'){
  311. $order = CloudStockTwoFillOrder::findOne([['id' => $params['order_id']]]);
  312. $order->is_first = 1;
  313. $order->save();
  314. }
  315. $upgrade = true;
  316. break;
  317. }
  318. }
  319. return $upgrade;
  320. }
  321. protected static function condition1($checked_condition_values, $key, $params)
  322. {
  323. $user_id = $params['user_id'];
  324. $child_user_ids = User::find()->where(['parent_id'=>$user_id])->asArray()->all();
  325. $level_arr = [];
  326. $use_level_arr = [];
  327. foreach ($checked_condition_values[$key]['value'] as $val) {
  328. if ($val['is_use']) $use_level_arr[] = $val['level'];
  329. }
  330. $user_id_arr = array_column($child_user_ids, 'id');
  331. $agent_list = CloudStockTwoAgent::lists(['where' => [['user_id' => $user_id_arr], ['level' => $use_level_arr], ['status' => StatusEnum::ENABLED]]]);
  332. foreach ($agent_list as $val) {
  333. if (isset($level_arr[$val['level']])) {
  334. $level_arr[$val['level']] += 1;
  335. } else {
  336. $level_arr[$val['level']] = 1;
  337. }
  338. }
  339. $upgrade = true;
  340. foreach ($checked_condition_values[$key]['value'] as $val) {
  341. if ($val['is_use'] && !empty($val['num'])) {
  342. if (empty($level_arr[$val['level']]) || $level_arr[$val['level']] < $val['num']) {
  343. $upgrade = false;
  344. continue;
  345. }
  346. }
  347. }
  348. return $upgrade;
  349. }
  350. // protected static function condition2($checked_condition_values, $key, $params)
  351. // {
  352. // $user_id = $params['user_id'];
  353. // $value_goods_ids = array_column($checked_condition_values[$key]['value'], 'id');
  354. // //条件 radio_type=1 表示或(满足其一);radio_type=2 表示与(同时满足)
  355. // $radio_type = isset($checked_condition_values[$key]["radio_type"]) ? $checked_condition_values[$key]["radio_type"] : 1;
  356. // $fill_order_list = CloudStockTwoFillOrder::lists(['where' => [['user_id' => $user_id], ['goods_id' => $value_goods_ids], ['is_pay' => 1]],
  357. // 'select' => 'sum(num) as num,goods_id',
  358. // 'group' => 'goods_id',
  359. // 'index' => 'goods_id'
  360. // ]);
  361. // //0待付款 1待发货 2 已发货 3已收货 4已完成 -1申请售后 -2售后中 -3售后完成 -4 已关闭 -5撤销售后】
  362. // $order_detail_list = OrderDetail::lists(['where' => [['user_id' => $user_id], ['goods_id' => $value_goods_ids], ['order_status' => [1, 2, 3, 4, -5]]],
  363. // 'select' => 'sum(num) as num,goods_id',
  364. // 'group' => 'goods_id',
  365. // 'index' => 'goods_id'
  366. // ]);
  367. // if ($radio_type == 1) {
  368. // $upgrade = false;
  369. // foreach ($checked_condition_values[$key]['value'] as $row) {
  370. // $num = 0;
  371. // if (!empty($fill_order_list[$row['id']]['num'])) $num += $fill_order_list[$row['id']]['num'];
  372. // if (!empty($order_detail_list[$row['id']]['num'])) $num += $order_detail_list[$row['id']]['num'];
  373. // if ($num >= $row['num']) {
  374. // $upgrade = true;
  375. // break;
  376. // }
  377. // }
  378. // } else {
  379. // $upgrade = true;
  380. // if (empty($checked_condition_values[$key]['value'])) {
  381. // $upgrade = false;
  382. // } else {
  383. // foreach ($checked_condition_values[$key]['value'] as $row) {
  384. // $num = 0;
  385. // if (!empty($fill_order_list[$row['goods_id']])) $num += $fill_order_list[$row['goods_id']];
  386. // if (!empty($order_detail_list[$row['goods_id']])) $num += $order_detail_list[$row['goods_id']];
  387. // if ($num < $row['num']) {
  388. // $upgrade = false;
  389. // break;
  390. // }
  391. // }
  392. // }
  393. // }
  394. // return $upgrade;
  395. // }
  396. protected static function condition2($checked_condition_values, $key, $params)
  397. {
  398. $user_id = $params['user_id'];
  399. $child_user_ids = User::find()->where(['parent_id'=>$user_id])->asArray()->all();
  400. $level_arr = [];
  401. $use_level_arr = [];
  402. foreach ($checked_condition_values[$key]['value'] as $val) {
  403. if ($val['is_use']) $use_level_arr[] = $val['level'];
  404. }
  405. $user_id_arr = array_column($child_user_ids, 'id');
  406. $agent_list = CloudStockTwoAgent::lists(['where' => [['user_id' => $user_id_arr], ['level' => $use_level_arr], ['status' => StatusEnum::ENABLED]]]);
  407. $user_id_arr = array_column($agent_list, 'user_id');
  408. $order_list = CloudStockTwoFillOrder::find()
  409. ->where(['user_id'=>$user_id_arr,'is_pay'=>1])
  410. ->select('sum(pay_money) as pay_money,user_id')
  411. ->groupBy('user_id')
  412. ->indexBy('user_id')
  413. ->asArray()
  414. ->all();
  415. foreach ($agent_list as $val) {
  416. $price = $order_list[$val['user_id']]['pay_money'] ?? 0;
  417. if (isset($level_arr[$val['level']])) {
  418. $level_arr[$val['level']] += $price;
  419. } else {
  420. $level_arr[$val['level']] = $price;
  421. }
  422. }
  423. $upgrade = true;
  424. foreach ($checked_condition_values[$key]['value'] as $val) {
  425. if ($val['is_use'] && !empty($val['num'])) {
  426. if (!isset($level_arr[$val['level']]) || empty($level_arr[$val['level']]) || $level_arr[$val['level']] < $val['num']) {
  427. $upgrade = false;
  428. continue;
  429. }
  430. }
  431. }
  432. return $upgrade;
  433. }
  434. protected static function condition3($checked_condition_values, $key, $params)
  435. {
  436. $user_id = $params['user_id'];
  437. $upgrade = false;
  438. if($params['order_type'] == 'fill'){
  439. $nums = $checked_condition_values[$key]['nums'] ?? 0;
  440. $order = CloudStockTwoFillOrder::findOne([['id' => $params['order_id']]]);
  441. if ($order['pay_money']>=$nums && $user_id == $order['user_id']) $upgrade = true;
  442. $order->is_first = 1;
  443. $order->save();
  444. }
  445. return $upgrade;
  446. }
  447. protected static function condition4($checked_condition_values, $key, $params)
  448. {
  449. $user_id = $params['user_id'];
  450. $first_child_user_ids = User::find()->where(['parent_id'=>$user_id])->asArray()->all();
  451. $child_id_arr = UserPartitionRelationship::getChildIdArr($user_id);
  452. $level_arr = [];
  453. $direct_level = [];
  454. $use_level_arr = [];
  455. foreach ($checked_condition_values[$key]['value'] as $val) {
  456. if ($val['is_use']) $use_level_arr[] = $val['level'];
  457. }
  458. $user_id_arr = array_column($first_child_user_ids, 'id');
  459. $agent_list = CloudStockTwoAgent::lists(['where' => [['user_id' => $child_id_arr], ['level' => $use_level_arr], ['status' => StatusEnum::ENABLED]]]);
  460. foreach ($agent_list as $val) {
  461. if (isset($level_arr[$val['level']])) {
  462. $level_arr[$val['level']] += 1;
  463. } else {
  464. $level_arr[$val['level']] = 1;
  465. }
  466. if(in_array($val['user_id'],$user_id_arr)){
  467. if (isset($direct_level[$val['level']])) {
  468. $direct_level[$val['level']] += 1;
  469. } else {
  470. $direct_level[$val['level']] = 1;
  471. }
  472. }
  473. }
  474. $upgrade = true;
  475. foreach ($checked_condition_values[$key]['value'] as $val) {
  476. if ($val['is_use'] && !empty($val['num'])) {
  477. if (!isset($level_arr[$val['level']]) || empty($level_arr[$val['level']]) || $level_arr[$val['level']] < $val['num']) {
  478. $upgrade = false;
  479. continue;
  480. }
  481. }
  482. if ($val['is_use'] && !empty($val['direct_num'])) {
  483. if (!isset($direct_level[$val['level']]) || empty($direct_level[$val['level']]) || $direct_level[$val['level']] < $val['direct_num']) {
  484. $upgrade = false;
  485. continue;
  486. }
  487. }
  488. }
  489. return $upgrade;
  490. }
  491. }