Promotion.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace common\globals;
  3. use common\enums\StatusEnum;
  4. use common\logic\common\AddonsLimit;
  5. use common\models\common\Addons;
  6. class Promotion extends BaseGlobal
  7. {
  8. ##########################################################################################################
  9. # 推广中心返回数据格式
  10. // #[
  11. # 'Achievement' => ['total_commission' => 0,'is_install' => true, 'name' => '业绩奖励'],
  12. # 'Agent' => ['total_commission' => 0,'is_install' => true, 'name' => '经销分红'],
  13. # 'Area' => ['total_commission' => 0,'is_install' => true, 'name' => '区域管理'],
  14. # 'Boss' => ['total_commission' => 0,'is_install' => true, 'name' => 'Boss'],
  15. #];
  16. ##########################################################################################################
  17. /**
  18. * 获取推广中心列表内容
  19. * @param [type] $invokes
  20. * @param array $params
  21. * @return array
  22. */
  23. public function getPromotion($invokes, $params = [])
  24. {
  25. $return = $name_arr = [];
  26. foreach ($invokes as $invoke) {
  27. try {
  28. // 检查是否安装插件
  29. if (AddonsLimit::goodsModel($invoke['addons_name'], $params['mall_id']) == false) continue;
  30. // 获取跟人对应插件资产
  31. $params['addons_name'] = $invoke['addons_name'];
  32. $data = $this->invoke($invoke['class'], $invoke['method'], $params);
  33. $is_success = $this->validateInvokeReturn($params['invoke_id'], $data);
  34. if ($is_success) {
  35. if(empty($data)){
  36. continue;
  37. }
  38. } else {
  39. throw new \Exception('结果数据格式校验未通过');
  40. }
  41. $return[$invoke['addons_name']] = $data;
  42. // 获取插件名称
  43. $name_arr[] = $invoke['addons_name'];
  44. } catch (\Exception $e) {
  45. \Yii::error('全局调用(INVOKE_GET_WITHDRAW_COND)出错:' . $invoke['class'] . '->' . $invoke['method'] . 'msg:' . $e->getMessage());
  46. continue;
  47. }
  48. }
  49. // 获取插件名称
  50. $addons = Addons::find()->select('name,title')->where(['name' => $name_arr, 'status' => StatusEnum::ENABLED])->asArray()->indexBy('name')->all();
  51. foreach ($addons as $name => $addon) {
  52. $return[$name]['name'] = $return[$name]['rename'] ?? $addon['title'];
  53. }
  54. return $return;
  55. }
  56. /**
  57. * 验证调用结果
  58. * @param [type] $return
  59. * @return boolean
  60. */
  61. protected function validateGetPromotion($return = null): bool
  62. {
  63. return true;
  64. }
  65. }