PointPageController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /****************************************************************
  3. * Author: libaojia
  4. * Date: 2017/9/7 下午2:15
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * User: 芸众商城 www.yunzshop.com
  8. ****************************************************************/
  9. namespace app\frontend\modules\finance\controllers;
  10. use app\common\components\ApiController;
  11. use app\common\facades\Setting;
  12. use app\common\services\password\PasswordService;
  13. use app\frontend\models\Member;
  14. use app\frontend\modules\finance\models\PointLog;
  15. class PointPageController extends ApiController
  16. {
  17. /**
  18. * @var Member
  19. */
  20. private $memberModel;
  21. public function index()
  22. {
  23. $this->getMemberInfo();
  24. if (!$this->memberModel) return $this->errorJson('未获取到会员信息');
  25. $result = $this->apiData();
  26. if (!versionCompare('1.1.138') || !miniVersionCompare('1.1.138')) {
  27. $result = $this->oldApiData();
  28. }
  29. return $this->successJson('ok', $result);
  30. }
  31. /**
  32. * 1.1.137版本及之前接口
  33. * @return array
  34. */
  35. private function oldApiData()
  36. {
  37. $setting = Setting::get('point.set');
  38. $return_data = [
  39. 'credit1' => $this->memberModel->credit1,
  40. 'transfer' => $this->getTransferStatus(),
  41. 'is_transfer_integral' => $this->getTransferIntegralStatus(),//转化消费积分
  42. 'activity' => $this->getActivityStatus(),
  43. 'rate' => $this->getRateSet(),
  44. 'lan_plugin' => $this->lanPlugin(),
  45. 'lan_name' => $this->lanName(),
  46. 'has_password' => $this->hasPassword(),
  47. 'need_password' => $this->needPassword(),
  48. 'exchange_to_love_by_member' => app('plugins')->isEnabled('love') && $setting['exchange_to_love_by_member'] ? 1 : 0,
  49. 'transfer_integral' => floatval($setting['transfer_integral']) ? floatval($setting['transfer_integral']) + 0 : 1,
  50. 'transfer_integral_love' => floatval($setting['transfer_integral_love']) ? floatval($setting['transfer_integral_love']) + 0 : 1,
  51. ];
  52. if (app('plugins')->isEnabled('point-exchange')) {
  53. if (($setting = \Yunshop\PointExchange\services\SettingService::getSetting())['open_state']) {
  54. $return_data['point_exchange'] = [
  55. 'name' => '积分通转兑',
  56. 'out_rate' => 1,
  57. 'in_rate' => bcdiv($setting['exchange_percent'], 100, 2),
  58. ];
  59. }
  60. }
  61. return $return_data;
  62. }
  63. /**
  64. * 1.1.138版本接口
  65. * @return array
  66. */
  67. private function apiData()
  68. {
  69. $setting = Setting::get('point.set');
  70. $arr = [
  71. 'credit1' => $this->memberModel->credit1,
  72. 'transfer' => $this->getTransferStatus(),
  73. 'is_transfer_integral' => $this->getTransferIntegralStatus(),//转化消费积分
  74. 'rate' => $this->getRateSet(),
  75. 'has_password' => $this->hasPassword(),
  76. 'need_password' => $this->needPassword(),
  77. 'other' => [],
  78. 'latest_record'=>(new PointLog())->getLatestRecord($this->memberModel->uid),
  79. 'point_task_switch'=>$this->getPointTaskStatus(),
  80. 'transfer_integral' => floatval($setting['transfer_integral']) ? floatval($setting['transfer_integral']) + 0 : 1,
  81. 'transfer_integral_love' => floatval($setting['transfer_integral_love']) ? floatval($setting['transfer_integral_love']) + 0 : 1,
  82. ];
  83. $pointName=Setting::get('shop.shop')['credit1'] ?: "积分";
  84. if($this->getActivityStatus()){
  85. $arr['other']['activity']=
  86. [
  87. 'img'=>'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2Fintegral%2Fimage10.png',
  88. 'name'=>$pointName.'活动'
  89. ];
  90. }
  91. if($this->lanPlugin()&&request()->type!=2){
  92. $arr['other']['lan_plugin']=[
  93. 'name'=>$this->lanName(),
  94. 'img'=>'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2Fintegral%2Fimage7.png'
  95. ];
  96. }
  97. if($this->getTransferIntegralStatus()){
  98. $integralName = \Yunshop\Integral\Common\Services\SetService::getIntegralName();
  99. $arr['other']['transfer_integral']=[
  100. 'img'=>'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2Fintegral%2Fimage8.png',
  101. 'name'=>$pointName.'转化'.$integralName
  102. ];
  103. }
  104. if(app('plugins')->isEnabled('love')&&$setting['exchange_to_love_by_member'] ? 1 : 0){
  105. $name=$pointName.'转'.(Setting::get('love.name')?Setting::get('love.name'):'爱心值');
  106. $arr['other']['exchange_to_love_by_member']=[
  107. 'img'=>'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2Fintegral%2Fimage9.png',
  108. 'name'=>$name
  109. ];
  110. }
  111. if (app('plugins')->isEnabled('point-exchange')) {
  112. if (($setting = \Yunshop\PointExchange\services\SettingService::getSetting())['open_state']) {
  113. $arr['other']['point_exchange'] = [
  114. 'img' => 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/plugin/distribution.png',
  115. 'name' => '积分通转兑',
  116. ];
  117. }
  118. }
  119. if(empty($arr['other'])){
  120. $arr['other']=false;
  121. }
  122. return $arr;
  123. }
  124. private function lanPlugin()
  125. {
  126. return (int)app('plugins')->isEnabled('point_exchange')&&\Setting::get('plugin.point-exchange.is_open_point_exchange');
  127. }
  128. private function lanName()
  129. {
  130. $set = Setting::get('plugin.point-exchange');
  131. return empty($set['plugin_name']) ? "蓝牛积分" : $set['plugin_name'];
  132. }
  133. private function hasPassword()
  134. {
  135. return $this->memberModel->yzMember->hasPayPassword();
  136. }
  137. private function needPassword()
  138. {
  139. return (new PasswordService())->isNeed('point', 'transfer');
  140. }
  141. // 获取积分任务状态
  142. private function getPointTaskStatus()
  143. {
  144. return app('plugins')->isEnabled('point-task')&&Setting::get('plugin.point-task.point_task_enable');
  145. }
  146. private function getTransferStatus()
  147. {
  148. return Setting::get('point.set.point_transfer') ? true : false;
  149. }
  150. private function getTransferIntegralStatus()
  151. {
  152. return app('plugins')->isEnabled('integral') && Setting::get('point.set.is_transfer_integral') ? true : false;
  153. }
  154. private function getActivityStatus()
  155. {
  156. return app('plugins')->isEnabled('point-activity');
  157. }
  158. private function getMemberInfo()
  159. {
  160. return $this->memberModel = Member::where('uid', $this->getMemberId())->first();
  161. }
  162. private function getMemberId()
  163. {
  164. return \YunShop::app()->getMemberId();
  165. }
  166. private function getRateSet()
  167. {
  168. return intval(Setting::get('point.set.point_transfer_poundage')) / 100 ?: 0;
  169. }
  170. }