Browse Source

添加编辑套餐,就生成小程序码

lizhen_gitee 1 year ago
parent
commit
2021a9ec96

+ 9 - 8
application/admin/controller/Package.php

@@ -110,11 +110,12 @@ class Package extends Backend
             }
             $result = $this->model->allowField(true)->save($params);
 
-            $this->getMiniCode($this->model->id,[],$this->auth->company_id);
+            $fileName = md5($this->model->id);
+            $fileUrl = '/uploads/package/'.$fileName.'.png';
+            Db::name('package')->where('id',$this->model->id)->update(['mini_code'=>$fileUrl]);
 
             Db::commit();
-
-
+            $this->getMiniCode($this->model->id,[],$this->auth->company_id);
 
         } catch (ValidateException|PDOException|Exception $e) {
         Db::rollback();
@@ -158,11 +159,15 @@ class Package extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                 $row->validateFailException()->validate($validate);
             }
+
+            $fileName = md5($ids);
+            $fileUrl = '/uploads/package/'.$fileName.'.png';
+            $params['mini_code']  = $fileUrl;
             $result = $row->allowField(true)->save($params);
+            Db::commit();
 
             $this->getMiniCode($ids,$row,$row['company_id']);
 
-            Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
         Db::rollback();
         $this->error($e->getMessage());
@@ -191,10 +196,6 @@ class Package extends Backend
             $code = $res2->getBody()->getContents();
             file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code);
 
-            $companyRes = Db::name('package')->where('id',$id)->update(['mini_code'=>$fileUrl]);
-            if ($companyRes === false) {
-                //$this->error('生成套餐小程序码失败');
-            }
             $miniCode = $httpStr.$fileUrl;
         } else {
             $miniCode = $httpStr.$package['mini_code'];

+ 11 - 4
application/api/controller/company/Package.php

@@ -77,6 +77,12 @@ class Package extends Apic
             if (!$package_id) {
                 throw new Exception('添加套餐失败');
             }
+
+            $fileName = md5($package_id);
+            $fileUrl = '/uploads/package/'.$fileName.'.png';
+            Db::name('package')->where('id',$package_id)->update(['mini_code'=>$fileUrl]);
+
+
             if (isset($data['type']) && $data['type'] == 2) {
                 $gift_data = input('gift_data','','trim');
                 $gift_data = json_decode(htmlspecialchars_decode($gift_data),true);
@@ -174,10 +180,15 @@ class Package extends Apic
             $data = request_post_hub($field);
             $data['updatetime'] = time();
 
+            $fileName = md5($id);
+            $fileUrl = '/uploads/package/'.$fileName.'.png';
+            $data['mini_code']  = $fileUrl;
+
             $packageRes = Db::name('package')->where('id',$id)->update($data);
             if (!$packageRes) {
                 throw new Exception('套餐编辑失败');
             }
+
             if ($check['type'] == 2) {
                 $packageGiftWhere['package_id'] = $id;
                 $packageGiftData = Db::name('package_gift')->where($packageGiftWhere)->select();
@@ -284,10 +295,6 @@ class Package extends Apic
             $code = $res2->getBody()->getContents();
             file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code);
 
-            $companyRes = Db::name('package')->where('id',$id)->update(['mini_code'=>$fileUrl]);
-            if ($companyRes === false) {
-                //$this->error('生成套餐小程序码失败');
-            }
             $miniCode = $httpStr.$fileUrl;
         } else {
             $miniCode = $httpStr.$package['mini_code'];