| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2018/10/11
- * Time: 13:47
- */
- namespace app\frontend\modules\finance\controllers;
- use app\backend\modules\finance\models\Advertisement;
- use app\backend\modules\income\Income;
- use app\common\components\ApiController;
- use app\common\exceptions\AppException;
- use app\frontend\modules\finance\services\PluginSettleService;
- use Illuminate\Support\Facades\DB;
- use Yunshop\StoreCashier\common\services\AdvertisementService;
- class PluginSettleController extends ApiController
- {
- public function pluginList()
- {
- $list = [];
- $config = \app\backend\modules\income\Income::current()->getItems();
- foreach ($config as $key => $value) {
- $list[] = $this->available($key, $value);
- }
- $list = array_filter($list);
- sort($list);
- if ($list) {
- return $this->successJson('获取数据成功', $list);
- }
- return $this->errorJson('未开启手动结算');
- }
- protected function available($key, $value)
- {
- $lang = \Setting::get('shop.lang', ['lang' => 'zh_cn'])['zh_cn'];
- $arr = [];
- switch ($key) {
- case 'merchant':
- if (\Setting::get('plugin.merchant.settlement_model')) {
- $arr = [
- 'title' => $value['title'],
- 'type' => $value['type'],
- 'amount'=> $value['class']::getNotSettleAmount(\YunShop::app()->getMemberId()),
- 'api' => 'finance.plugin-settle.plugin-merchant',
- 'icon' => 'income_d',
- ];
- }
- break;
- case 'commission':
- if (\Setting::get('plugin.commission.settlement_model')) {
- $arr = [
- 'title' => $value['title'],
- 'type' => $value['type'],
- 'amount'=> $value['class']::getNotSettleAmount(\YunShop::app()->getMemberId()),
- 'api' => 'finance.plugin-settle.plugin-commission',
- 'icon' => 'income_a',
- ];
- }
- break;
- case 'areaDividend':
- if (\Setting::get('plugin.area_dividend.settlement_model')) {
- $arr = [
- 'title' => $lang['area_dividend']['title']?:$value['title'],
- 'type' => $value['type'],
- 'amount'=> $value['class']::getNotSettleAmount(\YunShop::app()->getMemberId()),
- 'api' => 'finance.plugin-settle.plugin-area-dividend',
- 'icon' => 'income_c',
- ];
- }
- break;
- case 'teamDividend':
- if (\Setting::get('plugin.team_dividend.settlement_model')) {
- $arr = [
- 'title' => $lang['team_dividend']['title']?:$value['title'],
- 'type' => $value['type'],
- 'amount'=> $value['class']::getNotSettleAmount(\YunShop::app()->getMemberId()),
- 'api' => 'finance.plugin-settle.plugin-team-dividend',
- 'icon' => 'income_b',
- ];
- }
- break;
- case 'weeklyRewards':
- $week = array_pluck(\Setting::getAllByGroup('weekly-rewards')->toArray(), 'value', 'key');
- if ($week['dividend_settle'] || $week['area_settle']) {
- $arr = [
- 'title' => $value['title'],
- 'type' => $value['type'],
- 'amount'=> $value['class']::getNotSettleAmount(\YunShop::app()->getMemberId()),
- 'api' => 'finance.plugin-settle.plugin-weekly-rewards',
- 'icon' => 'income_e',
- ];
- }
- break;
- default:
- $arr = [];
- }
- return $arr;
- }
- //获取插件可结算佣金列表
- public function getNotSettleList()
- {
- $type = \YunShop::request()->plugin_type;
- $member_id = \YunShop::app()->getMemberId();
- if (empty($type) || empty($member_id)) {
- throw new AppException('参数错误');
- }
- $plugin_income = Income::current()->getItem($type);
- $class = array_get($plugin_income,'class');
- $function = 'getNotSettleInfo';
- if(class_exists($class) && method_exists($class,$function) && is_callable([$class,$function])){
- $result = $class::$function(['member_id' => $member_id])->orderBy('id', 'desc')->paginate(20);
- } else {
- throw new AppException('不存在的类');
- }
- if ($result->isEmpty()) {
- return $this->errorJson('暂无数据', []);
- }
- $data_processing = PluginSettleService::create($type);
- if (is_null($data_processing)) {
- throw new AppException('数据处理出错');
- }
- $data = [
- 'type' => $type,
- 'total' => $result->total(),
- 'per_page' => $result->perPage(),
- 'last_page' => $result->lastPage(),
- 'data' => $data_processing->sameFormat($result),
- ];
- return $this->successJson('获取数据成功', $data);
- }
- public function incomeReceive()
- {
- $id = intval(\YunShop::request()->id);
- $type = \YunShop::request()->plugin_type;
- if (empty($type) || empty($id)) {
- throw new AppException('参数错误');
- }
- $plugin_income = Income::current()->getItem($type);
- $class = array_get($plugin_income,'class');
- $function = 'getNotSettleInfo';
- if(class_exists($class) && method_exists($class,$function) && is_callable([$class,$function])){
- $result = $class::$function(['id' => $id])->first();
- } else {
- throw new AppException('不存在的类');
- }
- if (empty($result)) {
- throw new AppException('记录不存在');
- }
- //修改为已结算,加入收入
- $data_processing = PluginSettleService::create($type);
- $income_data = $data_processing->getAdvFormat($result);
- if (app('plugins')->isEnabled('store-cashier')) {
- $info = AdvertisementService::getStoreAdv($income_data);
- if ($info['status'] == 1) {
- $info['income_data'] = $income_data;
- return $this->successJson('成功', $info);
- }
- }
- return $this->successJson('成功', $this->getShopAdv($income_data));
- }
- protected function getShopAdv($income_data)
- {
- $adv = Advertisement::getOneData()->first();
- $lat = \YunShop::request()->lat;
- $lng = \YunShop::request()->lng;
- if ((!empty($lat) && !is_numeric($lat)) || (!empty($lng) && !is_numeric($lng))) {
- throw new AppException('参数错误');
- }
- if ($lat && $lng) {
- $res = Advertisement::uniacid()
- ->select(DB::raw("id, thumb, adv_url, longitude, latitude,(round(6367000 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$lat} * pi()) / 180) / 2), 2) + cos(({$lat} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$lng} * pi()) / 180) / 2), 2))))) as distance"))
- ->Status()
- ->where('area_open',1)
- ->orderBy('distance', 'asc')
- ->orderBy('sort_by', 'desc')
- ->first();
- if ($res) $adv = $res;
- }
- return [
- 'status' => 1,
- 'income_data' => $income_data,
- 'adv_thumb' => $adv->thumb ? yz_tomedia($adv->thumb) : '',
- 'adv_url' => $adv->adv_url ? $adv->adv_url : '',
- 'type' => 'shop',
- ];
- }
- //招商分红
- public function pluginMerchant()
- {
- }
- //分销佣金
- public function pluginCommission()
- {
- }
- //经销商提成
- public function pluginTeamDividend()
- {
- // $member_id = \YunShop::app()->getMemberId();
- //
- // $config = \Config::get('income.merchant');
- }
- //区域分红
- public function pluginAreaDividend()
- {
- }
- //周度奖励
- public function pluginWeeklyRewards()
- {
- }
- }
|