| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- namespace common\services;
- use Yii;
- use linslin\yii2\curl;
- use common\components\dict;
- use common\components\stringUtil;
- use common\components\wxUtil;
- use common\models\xhMerchant;
- use common\models\xhAdmin;
- use common\components\util;
- class xhMerchantService
- {
-
- /**
- * 是否认证的公众号,服务号
- */
- public static function isAuth($id)
- {
- $merchant = self::getById($id);
- $style = $merchant['accountStyle'];
- $authAccount = dict::getDict('merchant', 'authAccount');
- return in_array($style, $authAccount);
- }
-
- /**
- * 保存公众号二维码
- * @return string
- */
- public static function qrCodeSave($url, $wxAppId)
- {
- return '';
- $directory = dict::getDict('imgSavePath', 'wxMpQrcode');
- $path = Yii::getAlias('@webroot') . '/../../images';
- $pre = '/' . $directory . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
- if (!file_exists($path . $pre)) {
- mkdir($path . $pre, 0777, true);
- }
- $randString = stringUtil::buildOrderNo();
- $id = substr($wxAppId, -2);
- $name = $id . '_' . $randString . '.jpg';
- $fullFileName = $path . $pre . $name;
- $fileName = $pre . $name;
- $curl = new curl\Curl();
- $result = $curl->get($url);
- $fp2 = @fopen($fullFileName, 'a');//文件大小
- fwrite($fp2, $result);
- fclose($fp2);
- return $fileName;//默认大小 大
- }
-
- /**
- * 保存logo
- * @return string
- */
- public static function logoSave($url, $wxAppId)
- {
- return '';
- $directory = dict::getDict('imgSavePath', 'wxMpAvatar');
- $path = Yii::getAlias('@webroot') . '/../../images';
- $pre = '/' . $directory . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
- if (!file_exists($path . $pre)) {
- mkdir($path . $pre, 0777, true);
- }
- $randString = stringUtil::buildOrderNo();
- $id = substr($wxAppId, -2);
- $name = $id . '_' . $randString . '.jpg';
- $fullFileName = $path . $pre . $name;
- $fileName = $pre . $name;
- $curl = new curl\Curl();
- $result = $curl->get($url);
- $fp2 = @fopen($fullFileName, 'a');//文件大小
- fwrite($fp2, $result);
- fclose($fp2);
-
- $dstImg200 = $path . $pre . $id . '_' . $randString . '_200.jpg';//缩略宽 200px 中
- util::img2thumb($fullFileName, $dstImg200, 200, 0, 0, 0);
-
- $dstImg50 = $path . $pre . $id . '_' . $randString . '_50.jpg';//缩略成宽50px 小
- util::img2thumb($fullFileName, $dstImg50, 50, 0, 0, 0);
- return $fileName;//默认大小 大
- }
-
- /**
- * 传入最大的logo,输出三种logo:大 中 小
- */
- public static function getLogoList($largeImg)
- {
- $extend = substr($largeImg, strrpos($largeImg, '.') + 1);
- $pre = substr($largeImg, 0, strrpos($largeImg, '.'));
- return ['small' => $pre . '_50.' . $extend, 'medium' => $pre . '_200.' . $extend, 'large' => $largeImg];
- }
-
- /**
- * 商家接入审核通过
- */
- public static function pass($admin)
- {
- $openId = $admin['openId'];
- $merchant = xhWxOpenService::getMerchant();
- $sjId = $merchant['id'];
- $allTM = xhTMessageService::getList($sjId);
- $shortTempId = 'OPENTM401915538';
- $tempId = $allTM[$shortTempId];
- $data = array(
- "touser" => $openId,
- "template_id" => $tempId,//模板id
- "url" => Yii::$app->params['adminUrl'] . "/main/approve?id={$merchant['id']}",
- "data" => array(
- "first" => array(
- "value" => "恭喜,您的公众号审核通过!",
- "color" => "#173177"
- ),
- "keyword1" => array(
- "value" => '审核通过',
- "color" => "#173177"
- ),
- "keyword2" => array(
- "value" => date("Y-m-d H:i:s"),
- "color" => "#173177"
- ),
- "remark" => array(
- "value" => '点此登陆后台查看详细',
- "color" => "#173177"
- )
- ),
- );
- wxUtil::sendTaskInform($data, $merchant);
- }
-
- public static function getById($id)
- {
- $merchant = xhMerchant::getByCondition(['id' => $id]);
- return $merchant;
- }
-
- public static function getByAccount($id)
- {
- $merchant = xhMerchant::getByCondition(['id' => $id]);
- return $merchant;
- }
-
- public static function getByAppId($appId)
- {
- $merchant = xhMerchant::getByCondition(['wxAppId' => $appId]);
- return $merchant;
- }
-
- public static function getByCondition($condition)
- {
- $merchant = xhMerchant::getByCondition($condition);
- return $merchant;
- }
-
- public static function getAllByCondition($condition)
- {
- return xhMerchant::getAllByCondition($condition);
- }
-
- public static function getOne()
- {
- $m = xhMerchant::find()->asArray()->one();
- return $m;
- }
-
- /**
- * 更新商家的缓存信息
- * @param int $id
- */
- public static function refreshMerchantInfo($id)
- {
- $merchant = xhMerchant::getById($id);
- $account = $merchant['id'];
- $appId = $merchant['wxAppId'];
- $accountKey = dict::getCacheKey('merchantAccount') . $account;
- $idKey = dict::getCacheKey('sjId') . $id;
- $appIdKey = dict::getCacheKey('merchantAppId') . $appId;
- Yii::$app->redis->executeCommand('DEL', [$accountKey]);
- Yii::$app->redis->executeCommand('DEL', [$idKey]);
- Yii::$app->redis->executeCommand('DEL', [$appIdKey]);
- self::getByAccount($account);
- self::getById($id);
- self::getByAppId($appId);
- }
-
- /**
- * 更新数据
- */
- public static function updateById($id, $post)
- {
- xhMerchant::updateById($id, $post);
- self::refreshMerchantInfo($id);
- }
-
- /**
- * 增加,返回数组
- */
- public static function add($data)
- {
- $merchant = xhMerchant::add($data);
- $id = $merchant['id'];
- self::refreshMerchantInfo($id);
- return $merchant;
- }
-
- /**
- * 传入最大的照片,输出三种照片:大 中 小
- */
- public static function getShopPhotoList($largeImg)
- {
- $extend = substr($largeImg, strrpos($largeImg, '.') + 1);
- $pre = substr($largeImg, 0, strrpos($largeImg, '.'));
- return ['small' => $pre . '_50.' . $extend, 'medium' => $pre . '_200.' . $extend, 'large' => $largeImg];
- }
-
- public static function getByName($name)
- {
- $merchant = xhMerchant::getByCondition(['name' => $name]);
- return $merchant;
- }
-
- public static function getAdmin($merchant)
- {
- $adminId = isset($merchant['adminId']) ? $merchant['adminId'] : 0;
- $admin = xhAdminService::getById($adminId);
- return $admin;
- }
-
- }
|