| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\controllers;
- use app\models\Admin;
- use app\models\Option;
- use app\models\SaasDistribution;
- use app\models\SaasHistory;
- use app\models\SaaSLeaguePriceLog;
- use app\models\SaasProfitCash;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\User;
- use app\models\Favorite;
- use app\modules\alliance\models\OrderMemberForm;
- use app\modules\alliance\models\OrderListForm;
- use app\modules\alliance\models\AddressSaveForm;
- use app\modules\alliance\models\BusinessMemberOrderPayDataForm;
- use app\modules\alliance\models\AddressSetDefaultForm;
- use app\modules\alliance\models\FavoriteAddForm;
- use app\modules\alliance\models\FavoriteListForm;
- //use app\modules\alliance\models\AddressSetDefaultForm;
- use app\models\Address;
- use app\models\SaasCoupon;
- use app\models\BrowseLog;
- use app\models\SharingReceiver;
- use app\utils\Ocr\OcrApi;
- use app\utils\OrderNo;
- use yii\data\Pagination;
- use yii\helpers\Json;
- use app\models\Purchase;
- use app\models\StoreCloud;
- /**
- * 用户
- */
- class SaasController extends BaseController
- {
- private $alliance_store_id = -1;
- public function behaviors()
- {
- return parent::behaviors();
- }
- private function getDefaultData()
- {
- $data = [
- 'orders' => [
- 'status_0' => [
- 'text' => '待付款',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-0.png',
- ],
- 'status_1' => [
- 'text' => '待发货',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-1.png',
- ],
- 'status_2' => [
- 'text' => '待收货',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-2.png',
- ],
- 'status_3' => [
- 'text' => '已完成',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-3.png',
- ],
- 'status_4' => [
- 'text' => '售后',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-4.png',
- ],
- ]
- ];
- return $data;
- }
- public function actionGetUserPrice()
- {
- $saasUser = get_saas_user();
- if (!$saasUser) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => "参数解析错误"
- ]);
- }
- $data = [
- 'share_profit' => $saasUser->share_profit,
- 'name' => $saasUser->name,
- 'avatar' => $saasUser->avatar
- ];
- return $this->asJson($data);
- }
- public function actionGetCategoryInfo()
- {
- $list = \app\models\SaasCategory::findAll(['is_delete' => 0]);
- return $this->asJson([
- 'code' => 0,
- 'data' => $list,
- ]);
- }
- /**
- * 用户中心
- * @return \yii\web\Response
- */
- public function actionIndex()
- {
- $data = $this->getDefaultData();
- $data = [
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success'
- ];
- $saasUser = get_saas_user();
- $is_admin = 0;
- $is_store_admin = 0;
- if ($saasUser) {
- $is_admin = !empty($saasUser->id) ? Admin::findOne(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type'=>"admin"]) : "";
- // 根据admin表中手机号判断当前是否为客户端管理员,后期需添加admin表中的手机号编辑
- $store_admin = Admin::find()->where(['mobile' => $saasUser->mobile, 'is_delete' => 0, 'type' => 'store'])->orderBy('id DESC')->one();
- if($store_admin){
- $is_store_admin = Store::findOne(['id' => $store_admin->type_id, 'is_delete' => 0]);
- }else{
- $is_store_admin = '';
- }
- }
- $storeCloud = StoreCloud::find()
- ->where(['is_delete' => 0, 'is_enable' => 1, 'saas_user_id' => $saasUser['id']])
- ->one();
-
- $is_can_distribution = $storeCloud && $storeCloud->store_id > 0 ? 1 : 0;// 是否有商城(是否可以铺货)
- $is_can_distribution = $is_can_distribution && $storeCloud['can_distribution'] ? 1 : 0;// 否具备 一键铺货选品的权限
- //店铺积分
- $store_integral = User::find()->alias('u')->leftJoin(['s' => Store::tableName()], 'u.store_id = s.id')
- ->where(['u.is_delete' => 0, 's.is_delete' => 0, 'binding' => $saasUser->mobile])->andWhere(['IS NOT', 's.id', NULL])->sum('u.integral') ?: 0;
- $user_data_info = [
- 'access_token' => $saasUser['access_token'],
- 'avatar_url' => $saasUser['avatar'],
- 'binding' => $saasUser['mobile'],
- 'id' => $saasUser['id'],
- 'nickname' => $saasUser['name'],
- 'saas_money' => $saasUser['share_profit'],
- 'is_salesman' => $saasUser['is_salesman'],
- 'is_admin' => empty($is_admin) ? 0 : 1,
- 'is_store_admin' => empty($is_store_admin) ? 0 : 1,
- 'gender' => $saasUser['gender'],
- 'is_purchase' => $storeCloud ? 1 : 0, // 是否为采购员
- 'is_can_distribution' => $is_can_distribution, // 是否有商城(是否可以铺货)
- 'can_distribution' => $storeCloud['can_distribution'] ?? 0, // 否具备 一键铺货选品的权限
- 'league_price' => $saasUser->league_price,
- 'integral' => $saasUser->integral,
- 'store_integral' => $store_integral
- ];
- $data['data']['user_info'] = $user_data_info;
- /**
- * 获取用户优惠券数量
- */
- $coupon_num = SaasCoupon::find()->where([
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0,
- 'is_use' => 0,
- 'is_expire' => 0,
- ])->count();
- /**
- * 获取浏览记录数量(包含商品和店铺的总数)
- */
- $browse_log_num = BrowseLog::find()->where([
- 'saas_id' => get_saas_user_id(),
- //'store_id' => get_store_id(),
- 'is_delete' => 0,
- ])->count();
- /**
- * 获取用户收藏商品数量
- */
- $favorite_goods_num = Favorite::find()->where([
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0
- ])->count();
- $order_count = OrderListForm::getCountData(get_saas_user_id());
- $distribution = SaasDistribution::findOne(['saas_id' => get_saas_user_id()]);
- $is_distribution = false;
- if (is_wechat_platform()) {
- if (!empty($distribution->platform_open_id)) {
- $is_distribution = true;
- }
- }
- if (is_alipay_platform()) {
- if (empty($distribution->ali_name)) {
- $is_distribution = true;
- }
- }
- // start 获取核销码
- // TODO 这里要做支付宝小程序兼容
- $code_url = '';
- if (isset($data['data']['user_info'])) {
- $data['data']['user_info']['is_can_wechat'] = 0;
- if (strpos($data['data']['user_info']['nickname'], '****') !== false) {
- $data['data']['user_info']['is_can_wechat'] = 1;
- }
- }
- $arr = [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'order_count' => $order_count,
- 'show_customer_service' => 1,
- 'user_info' => isset($data['data']['user_info']) ? $data['data']['user_info'] : null,
- 'orders' => $data['data']['orders'],
- 'coupon_num' => $coupon_num,
- 'favorite_goods_num' => $favorite_goods_num,
- 'browse_log_num' => $browse_log_num,
- 'code_url' => $code_url,
- 'is_distribution' => $is_distribution
- ],
- ];
- return $this->asJson($arr);
- }
- /**
- * 会员支付
- */
- public function actionSubmitMember()
- {
- $form = new OrderMemberForm();
- $form->saas_id = get_saas_user_id();
- $form->attributes = post_params();
- return $this->asJson($form->save());
- }
- /**
- * 支付
- * @return \yii\web\Response
- */
- public function actionMemberPayData()
- {
- $form = new BusinessMemberOrderPayDataForm();
- $form->attributes = post_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 假支付
- * @return \yii\web\Response
- */
- public function actionFpay(){
- $pay_price = get_params('price',0);
- $code = get_params('code');
- // $type = get_params('type');
- $goods_names = '测试支付';
- $form = new BusinessMemberOrderPayDataForm();
- return $this->asJson($form->falsePay($goods_names, $pay_price, $code));
- }
- /**
- * 设为默认收货地址
- * @return \yii\web\Response
- */
- public function actionAddressSetDefault()
- {
- $form = new AddressSetDefaultForm();
- $form->attributes = get_params();
- $form->store_id = $this->alliance_store_id;
- $form->user_id = get_saas_user_id();
- return $this->asJson($form->save());
- }
- /**
- * 收货地址详情
- * @return \Yii\web\Response
- */
- public function actionAddressDetail()
- {
- $form = new AddressSetDefaultForm();
- $form->address_id = get_params('id');
- $form->store_id = $this->alliance_store_id;
- $form->user_id = get_saas_user_id();
- return $this->asJson($form->info());
- }
- /**
- * 删除收货地址
- * @return \yii\web\Response
- */
- public function actionAddressDelete()
- {
- $form = new AddressSetDefaultForm();
- $form->attributes = get_params();
- $form->store_id = $this->alliance_store_id;
- $form->user_id = get_saas_user_id();
- return $this->asJson($form->delete());
- }
- /**
- * 保存收货地址
- * @return \yii\web\Response
- */
- public function actionAddressSave()
- {
- $form = new AddressSaveForm();
- $form->attributes = post_params();
- $form->store_id = $this->alliance_store_id;
- $form->user_id = get_saas_user_id();
- return $this->asJson($form->save());
- }
- /**
- * 获取收货地址
- * @return \yii\web\Response
- */
- public function actionAddressList()
- {
- $query = Address::find()->where([
- 'is_delete' => 0,
- 'user_id' => get_saas_user_id(),
- ]);
- $list = $query->orderBy('is_default DESC,addtime DESC')->select('id,name,mobile,province_id,province,city_id,city,district_id,district,detail,is_default')->asArray()->all();
- foreach ($list as $i => $item) {
- $list[$i]['address'] = $item['province'] . $item['city'] . $item['district'] . $item['detail'];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- ],
- ]);
- }
- /**
- * 获取信息
- * @return \yii\web\Response
- */
- public function actionOcrInfo() {
- $type = post_params('type');
- if (empty($type) || !in_array($type, OcrApi::$validType)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '类型参数错误'
- ]);
- }
- $side = post_params('side');
- if (empty($side) && $type == OcrApi::TYPE_ID_CARD) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '身份证参数有误'
- ]);
- }
- $url = post_params('url');
- if (empty($url)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '图片地址为空'
- ]);
- }
- try {
- $ocr = new OcrApi(true);
- switch ($type) {
- case OcrApi::TYPE_LICENSE:
- $res = $ocr->getBusinessLicense($url);
- break;
- case OcrApi::TYPE_ID_CARD:
- $res = $ocr->getIDCard($url, $side);
- break;
- case OcrApi::TYPE_BANK:
- $res = $ocr->getBankCard($url);
- break;
- case OcrApi::TYPE_TEXT:
- $res = $ocr->getTextRecognition($url, 1);
- break;
- }
- if ($res['code'] == 0 && !empty($res['data'])) {
- return $this->asJson($res);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取信息失败,请手动输入'
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionOtherInfo() {
- $cloud_supplier_banner = Option::get('cloud_supplier_banner', 0, 'saas', '')['value'];
- $admin_copyright = Option::get('store_apply_agreement', 0, 'saas', '')['value'];
- $cloud_supplier_apply_agreement = Option::get('cloud_supplier_apply_agreement', 0, 'saas', '')['value'];
- $supplier_custom_form = Option::get('supplier_custom_form', 0, 'saas', json_encode([]))['value'];
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'cloud_supplier_banner' => $cloud_supplier_banner ? Json::decode($cloud_supplier_banner) : [],
- 'store_apply_agreement' => $admin_copyright,
- 'cloud_supplier_apply_agreement' => $cloud_supplier_apply_agreement,
- 'supplier_custom_form' => json_decode($supplier_custom_form),
- ]
- ]);
- }
- /**
- * 联盟佣金提现提交
- */
- public function actionCashCommit() {
- $amount = post_params('amount');
- if ($amount < 0.01) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现最小金额不能小于0.01元'
- ]);
- }
- $user = !empty(get_user()) ? get_user() : User::find()->where(['binding'=>get_saas_user()->mobile])->one();
- $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
- if ($saas_user->share_profit < $amount) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前提现金额大于可提现联盟佣金'
- ]);
- }
- if (!$saas_user->platform_open_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请先绑定平台小程序openid'
- ]);
- }
- $t = \Yii::$app->db->beginTransaction();
- $cash = new SaasProfitCash();
- $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_SAAS_PROFIT_CASH);
- $cash->user_id = get_saas_user_id();
- $cash->mobile = $user->binding;
- $cash->amount = $amount;
- $cash->status = SaasProfitCash::CASH_STATUS_WAIT;
- $cash->created_at = time();
- if (!$cash->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $cash->errors[0]
- ]);
- }
- $cash->before_price = $saas_user->share_profit;
- $cash->after_price = ($saas_user->share_profit - $amount);
- $saas_user->share_profit = $saas_user->share_profit - $amount;
- $saas_user->save();
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '提交成功,请等待审核'
- ]);
- }
- /**
- * 联盟佣金提现列表
- */
- public function actionCashList() {
- $page = get_params('page', 1);
- $limit = get_params('limit', 10);
- $status = get_params('status', -1);
- $user = get_user();
- $query = SaasProfitCash::find()->where(['mobile' => !empty($user->binding) ? $user->binding : get_saas_user()->mobile]);
- if ($status > -1) {
- if ($status <= 2) {
- $query->andWhere(['status' => $status]);
- } else {
- $query->andWhere(['is_pay' => 1]);
- }
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select('*')->limit($pagination->limit)
- ->offset($pagination->offset)
- ->asArray()->orderBy(['created_at' => SORT_DESC])->all();
- foreach ($list as &$value) {
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['amount'] = sprintf("%.2f", ($value['amount'] - $value['service_money']));
- $value['status_text'] = $value['status'] == 0 ? '待审核' : ($value['status'] == 1 ? '已通过' : '已拒绝');
- if ($value['status'] == 1 && $value['is_pay'] == 1) {
- $value['status'] = 4;
- $value['status_text'] = '已打款';
- }
- $value['updated_at'] = $value['updated_at'] ? date('Y-m-d H:i:s', $value['updated_at']) : null;
- $value['status'] = (string)$value['status'];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list,
- ]
- ]);
- }
- public function actionAddHistory()
- {
- $saas_user_id = get_saas_user_id();
- if ($saas_user_id > 0) {
- $store_id = get_store_id();
- $history = SaasHistory::find()->where(['user_id' => $saas_user_id, 'store_id' => $store_id])->one();
- if ($history) {
- $history->updated_at = time();
- $history->save();
- } else {
- $history = new SaasHistory();
- $history->user_id = $saas_user_id;
- $history->store_id = $store_id;
- $history->updated_at = time();
- $history->save();
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '添加成功',
- ]);
- }
- public function actionGetHistory()
- {
- $page = get_params('page', 1);
- $limit = 10;
- $query = SaasHistory::find()->alias('sh')
- ->leftJoin(['s' => Store::tableName()], 'sh.store_id=s.id')
- ->select(['s.id', 's.name', 's.logo']);
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $query->limit($limit)->offset($pagination->offset);
- $list = $query->orderBy(['sh.updated_at' => SORT_DESC])->asArray()->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- ]);
- }
- /**
- * 喜欢的商品或店铺列表
- */
- public function actionCheckFavorite()
- {
- $is_favorite = Favorite::find()->where(['store_id'=>get_store_id(),'saas_id'=>get_saas_user_id(),'is_delete'=>0])->one();
- $storeInfo = Store::find()->where(['id'=>get_store_id(),'is_delete'=>0])->one();
- $store_name = '';
- if(isset($storeInfo->name)){
- $store_name = $storeInfo->name;
- }
- $status = (isset($is_favorite->id) && $is_favorite->id > 0) ? 1 : 0;
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data'=>[
- 'status' => $status,
- 'store_name' => $store_name
- ]
- ]);
- }
- /**
- * 添加商品或店铺到我的喜欢
- */
- public function actionFavoriteAdd()
- {
- $form = new FavoriteAddForm();
- $form->attributes = post_params();
- $form->store_id = get_store_id();
- $form->saas_id = get_saas_user_id();
- $form->user_id = 0;
- return $this->asJson($form->save());
- }
- /**
- * 喜欢的商品或店铺列表
- */
- public function actionFavoriteList()
- {
- $form = new FavoriteListForm();
- $form->attributes = get_params();
- $form->saas_id = get_saas_user_id();
- $form->user_id = 0;
- //$form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 取消喜欢的商品或店铺列表
- */
- public function actionRemoveFavorite()
- {
- $id = get_store_id();
- if (empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- // if (!is_array($id)) {
- // $res = Favorite::updateAll(['is_delete' => 1], ['goods_id' => $id, 'user_id' => get_user_id(), 'type' => post_params('type', 0)]);
- // } else {
- // $res = Favorite::updateAll(['is_delete' => 1], ['and', ['in', 'goods_id', $id], ['user_id' => get_user_id(), 'type' => post_params('type', 0)]]);
- // }
- $res = Favorite::updateAll(['is_delete' => 1], ['store_id' => $id, 'saas_id' => get_saas_user_id(), 'type' => post_params('type', 0)]);
- if ($res) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功',
- ]);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'fail',
- 'err' => $res
- ]);
- }
- }
- public function actionSearchKeyword()
- {
- $keyword = Option::get('search_keyword', 0, 'saas', json_encode([]));
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => json_decode($keyword['value']),
- ]);
- }
- //获取返利数据
- public function actionRebaseInfo(){
- $saas_id = get_saas_user_id();
- //echo $saas_id;exit;
- $receiverInfo = SharingReceiver::find()->where(['saas_id'=>$saas_id,'is_delete'=>0])->andWhere([
- 'or',['and',['is_pay'=>0]],['and',['is_pay'=>1]]
- ])->asArray()->all();
- $total = $finish = $nofinish = 0;
- foreach($receiverInfo as $val){
- $total += $val['amount'];
- if($val['is_pay'] == 0){
- $nofinish += $val['amount'];
- }
- if($val['is_pay'] == 1){
- $finish += $val['amount'];
- }
- }
- $data['total'] = $total;
- $data['nofinish'] = $nofinish;
- $data['finish'] = $finish;
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- //获取返利数据
- public function actionRebaseList(){
- $saas_id = get_saas_user_id();
- $status = get_params('status',-1);
- $page = get_params('page',1);
- $limit = 10;
- $query = SharingReceiver::find()->where(['saas_id'=>$saas_id,'is_delete'=>0]);
- if($status == -1){ //全部
- $query->andWhere([
- 'or',['and',['is_pay'=>0]],['and',['is_pay'=>1]]
- ]);
- }
- if($status == 0){ //未到账
- $query->andWhere(['is_pay'=>0]);
- }
-
- if($status == 1){ //已到账
- $query->andWhere(['is_pay'=>1]);
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $query->limit($limit)->offset($pagination->offset);
- $list = $query->orderBy(['id' => SORT_DESC])->select('is_pay,created_at,amount,remark')->asArray()->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => ['list'=>$list,'page'=>$page,'count'=>$count]
- ]);
- }
- /**
- * 获取联盟券记录
- */
- public function actionLeaguePriceLog() {
- $saas_user_id = get_saas_user()->id;
- $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']);
- $store = Store::findOne($admin->type_id);
- $send_or_take_type = get_params('send_or_take_type', -1);
- $type = get_params('type', -1);
- $query = SaaSLeaguePriceLog::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'role' => SaaSLeaguePriceLog::ROLE_STORE])
- ->select('id, type, send_or_take_type, league_price, addtime, saas_user_id')->orderBy('addtime desc');
- if (isset($send_or_take_type) && $send_or_take_type >= 0) {
- $query->andWhere(['send_or_take_type' => $send_or_take_type]);
- }
- if (isset($type) && in_array($type, [0, 1])) {
- $query->andWhere(['type' => $type]);
- }
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
- $item['type'] = (int)$item['type'];
- $item['send_or_take_type'] = (int)$item['send_or_take_type'];
- $item['name'] = '';
- $item['mobile'] = '';
- $item['avatar'] = '';
- if ($item['saas_user_id']) {
- $saasUser = SaasUser::findOne($item['saas_user_id']);
- if ($saasUser) {
- $item['name'] = $saasUser->name;
- $item['mobile'] = $saasUser->mobile;
- $item['avatar'] = $saasUser->avatar;
- }
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount']
- ]
- ]);
- }
- /**
- * 个人分账记录
- * @return \yii\web\Response
- */
- public function actionShareProfitRecord() {
- $page = get_params('page', 1);
- $limit = get_params('limit', 10);
- $saasUser = get_saas_user();
- $query = SharingReceiver::find()->where(['saas_id' => $saasUser->id]);
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select('*')->limit($pagination->limit)
- ->offset($pagination->offset)
- ->asArray()->orderBy(['created_at' => SORT_DESC])->all();
- foreach ($list as $key => $value) {
- $tmp = [];
- $tmp['order_no'] = $value['order_no'];
- $tmp['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $tmp['amount'] = $value['amount'];
- $tmp['remark'] = $value['remark'];
- $tmp['pay_status'] = $value['is_pay'] == 0 ? '待分账' : ($value['is_pay'] == 1 ? '已分账' : '分账失败-转佣金');
- $list[$key] = $tmp;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list,
- ]
- ]);
- }
- }
|