|
@@ -6,9 +6,12 @@ use app\BaseController;
|
|
|
use app\model\api\Product;
|
|
|
use app\model\system\Category as CategoryModel;
|
|
|
use app\model\system\ProductAttr;
|
|
|
+use app\model\system\Attachment;
|
|
|
use app\Request;
|
|
|
+use EasyWeChat\Factory;
|
|
|
use library\services\UtilService;
|
|
|
use library\services\QrcodeService;
|
|
|
+use library\services\upload\Upload as Upload;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class Index extends BaseController
|
|
@@ -133,4 +136,44 @@ class Index extends BaseController
|
|
|
return app('json')->successful($data);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 商品分享二维码
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function code(Request $request, $id)
|
|
|
+ {
|
|
|
+ if (!$id || !($storeInfo = Product::getValidProduct($id, 'id'))) return app('json')->fail('商品不存在或已下架');
|
|
|
+ $user = $request->user();
|
|
|
+ try {
|
|
|
+ //小程序
|
|
|
+ $name = $id . '_' . $user['uid'] . '_product.jpg';
|
|
|
+ $imageInfo = Attachment::getInfo($name, 'name');
|
|
|
+ if (!$imageInfo) {
|
|
|
+ $query = 'id=' . $id . '&uid=' . $user['uid'];
|
|
|
+ $mini = Factory::miniProgram(config('weixin')['mini_program']);
|
|
|
+ $res = $mini->app_code->getQrCode('pages/product/detail?'.$query, 280);
|
|
|
+ if (!$res) return app('json')->fail('二维码生成失败');
|
|
|
+ $upload = new Upload(2,config('upload')['stores']['qiniu']);
|
|
|
+ $res = $upload->to('routine/product')->validate()->stream($res, $name);
|
|
|
+ if ($res === false) {
|
|
|
+ return app('json')->fail($upload->getError());
|
|
|
+ }
|
|
|
+ $imageInfo = $upload->getUploadInfo();
|
|
|
+ $remoteImage = UtilService::remoteImage($imageInfo['dir']);
|
|
|
+ if (!$remoteImage['status']) return app('json')->fail('小程序二维码未能生成');
|
|
|
+ Attachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, 2, $imageInfo['time'], 2);
|
|
|
+ $url = $imageInfo['dir'];
|
|
|
+ } else $url = $imageInfo['att_dir'];
|
|
|
+ return app('json')->successful(['code' => $url]);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return app('json')->fail($e->getMessage(), [
|
|
|
+ 'code' => $e->getCode(),
|
|
|
+ 'line' => $e->getLine(),
|
|
|
+ 'message' => $e->getMessage()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|