| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- /**
- * MaterialController.php
- * todo 文件描述
- * Created on 2025/1/11 上午10:48
- * @author: hankaige
- */
- namespace app\modules\admin\controllers;
- use app\models\Color;
- use app\models\Qrcode;
- use app\modules\admin\models\material\CategoryForm;
- use app\modules\admin\models\material\MaterialForm;
- use app\modules\admin\models\QrcodeForm;
- use yii\helpers\Json;
- class MaterialController extends BaseController
- {
- public function actionMaterialCategoryList()
- {
- $form = new CategoryForm();
- $form->scenario = $form::SCENE_LIST;
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->getList());
- }
- public function actionMaterialCategoryEdit()
- {
- $form = new CategoryForm();
- $form->scenario = $form::SCENE_EDIT;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postEdit());
- }
- public function actionMaterialCategoryDelete()
- {
- $form = new CategoryForm();
- $form->scenario = $form::SCENE_DELETE;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postDelete());
- }
- public function actionMaterialCategoryStatus()
- {
- $form = new CategoryForm();
- $form->scenario = $form::SCENE_STATUS;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postStatus());
- }
- public function actionMaterialCategoryListNoPage()
- {
- $form = new CategoryForm();
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->getListNoPage());
- }
- public function actionMaterialList()
- {
- $form = new MaterialForm();
- $form->scenario = $form::SCENE_LIST;
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->getList());
- }
- public function actionMaterialEdit()
- {
- $form = new MaterialForm();
- $form->scenario = $form::SCENE_EDIT;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postEdit());
- }
- public function actionMaterialDelete()
- {
- $form = new MaterialForm();
- $form->scenario = $form::SCENE_DELETE;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postDelete());
- }
- public function actionMaterialStatus()
- {
- $form = new MaterialForm();
- $form->scenario = $form::SCENE_STATUS;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postStatus());
- }
- public function actionMaterialTop()
- {
- $form = new MaterialForm();
- $form->scenario = $form::SCENE_STATUS;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->postTop());
- }
- public function actionGetQrcodeSetting()
- {
- //兼容联盟
- $is_saas = get_params('is_saas', 0);
- if ($is_saas) {
- $store_id = -1;
- } else {
- $store_id = get_store_id();
- }
- $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_MATERIAL]);
- // \Yii::error($qrcode->font);
- $color = Color::find()->select('id, color')->andWhere(['is_delete' => 0])->asArray()->all();
- $font_position = json_decode($qrcode->font_position, TRUE);
- $qrcode_position = json_decode($qrcode->qrcode_position, TRUE);
- $avatar_position = json_decode($qrcode->avatar_position, TRUE);
- $avatar_size = json_decode($qrcode->avatar_size, TRUE);
- $qrcode_size = json_decode($qrcode->qrcode_size, TRUE);
- $font_size = json_decode($qrcode->font, TRUE);
- // \Yii::error($font_size);
- $first = Color::findOne(['color' => $font_size['color']]);
- $res = [
- 'qrcode_bg' => $qrcode->qrcode_bg ?: \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/2_1.png',
- 'qrcode_pic' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/1.png',
- 'avatar' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png',
- 'qrcode' => $qrcode,
- 'color' => $color,
- 'first' => $first->id,
- 'font_c' => Json::decode($qrcode->font, TRUE)['color'] ? Json::decode($qrcode->font, TRUE)['color'] : ($first->color ?: "#000"),
- 'avatar_w' => $avatar_size['w'] ?: '63',
- 'avatar_x' => $avatar_position['x'] ?: '50',
- 'avatar_y' => $avatar_position['y'] ?: '160',
- 'qrcode_w' => $qrcode_size['w'] ?: '169',
- 'qrcode_c' => empty($qrcode_size['c']) ? 1 : (($qrcode_size['c'] == "true") ? 1 : 0),
- 'qrcode_x' => $qrcode_position['x'] ?: '65',
- 'qrcode_y' => $qrcode_position['y'] ?: '240',
- 'font_x' => $font_position['x'] ?: '124',
- 'font_y' => $font_position['y'] ?: '180',
- 'font_w' => $font_size['size'] ?: '20',
- ];
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]);
- }
- public function actionQrcode()
- {
- $store_id = get_store_id();
- //兼容联盟
- $is_saas = post_params('is_saas', 0);
- if ($is_saas) {
- $store_id = -1;
- }
- $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_MATERIAL]);
- if (!$qrcode) {
- $qrcode = new Qrcode();
- }
- $form = new QrcodeForm();
- $form->attributes = post_params();
- $form->store_id = $store_id;
- $form->qrcode = $qrcode;
- $form->type = Qrcode::TYPE_MATERIAL;
- return $this->asJson($form->save());
- }
- //基础设置
- public function actionMaterialSetting()
- {
- $form = new MaterialForm();
- $form->scenario = $form::SCENE_SETTING;
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->materialSetting());
- }
- }
|