|
@@ -25,7 +25,8 @@ use app\common\model\content\Closure;
|
25
|
25
|
|
26
|
26
|
use app\common\model\shop\Shop as shopModel;
|
27
|
27
|
use app\common\model\content\EquiCategory as EquiCategoryModel;
|
28
|
|
-
|
|
28
|
+use app\common\model\shop\ShopHkLog;
|
|
29
|
+use think\facade\Db;
|
29
|
30
|
use think\facade\Event;
|
30
|
31
|
|
31
|
32
|
|
|
@@ -689,5 +690,130 @@ class ShopContentLogic extends Logic
|
689
|
690
|
return $data;
|
690
|
691
|
}
|
691
|
692
|
|
|
693
|
+ /**
|
|
694
|
+ * 加密 ZMH 2025-03-18
|
|
695
|
+ * @param $data
|
|
696
|
+ * @return bool|string
|
|
697
|
+ */
|
|
698
|
+ public static function encrypt($data)
|
|
699
|
+ {
|
|
700
|
+ $key = 'ABCDEFGHIJKLMNOP'; //16位
|
|
701
|
+ $vi = '0102030405060708'; //16位
|
|
702
|
+ if (is_array($data)) {
|
|
703
|
+ $str = json_encode($data,JSON_UNESCAPED_UNICODE); //讲数组转为字符串
|
|
704
|
+ } else if (is_string($data)) {
|
|
705
|
+ $str = $data;
|
|
706
|
+ } else {
|
|
707
|
+ return false;
|
|
708
|
+ }
|
|
709
|
+
|
|
710
|
+ $sign = openssl_encrypt($str, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $vi);
|
|
711
|
+ $sign = base64_encode($sign);
|
|
712
|
+ return $sign;
|
|
713
|
+ }
|
|
714
|
+
|
|
715
|
+ /**
|
|
716
|
+ * 获取商家信息 ZMH 2025-03-18
|
|
717
|
+ * @param $code
|
|
718
|
+ * @return model|bool
|
|
719
|
+ */
|
|
720
|
+ public static function getShopByCode($code)
|
|
721
|
+ {
|
|
722
|
+ if (empty($code)) {
|
|
723
|
+ self::$error = "设备编码不能为空";
|
|
724
|
+ self::$errCode = 2;
|
|
725
|
+ return false;
|
|
726
|
+ }
|
|
727
|
+
|
|
728
|
+ $where = [
|
|
729
|
+ "del" => 0,
|
|
730
|
+ "is_show" => 1,
|
|
731
|
+ "pid" => 0, //必须是电脑
|
|
732
|
+ "code" => $code
|
|
733
|
+ ];
|
|
734
|
+ $item = EquiCategoryModel::where($where)->find();
|
|
735
|
+ if (empty($item)) {
|
|
736
|
+ self::$error = "没有找到对应的设备";
|
|
737
|
+ self::$errCode = 3;
|
|
738
|
+ return false;
|
|
739
|
+ }
|
|
740
|
+
|
|
741
|
+ $shop = ShopModel::where("id", $item["shop_id"])->find();
|
|
742
|
+ if (empty($shop)) {
|
|
743
|
+ self::$error = "用户信息不存在";
|
|
744
|
+ self::$errCode = 4;
|
|
745
|
+ return false;
|
|
746
|
+ }
|
|
747
|
+
|
|
748
|
+ return $shop;
|
|
749
|
+ }
|
|
750
|
+
|
|
751
|
+ /**
|
|
752
|
+ * 获取剩余数量 ZMH 2025-03-18
|
|
753
|
+ * @param $get
|
|
754
|
+ * @return bool|number
|
|
755
|
+ */
|
|
756
|
+ public static function getHKSYCount($get) {
|
|
757
|
+ $code = $get["code"] ?? '';
|
|
758
|
+ $shop = self::getShopByCode($code);
|
|
759
|
+ if (empty($shop)) {
|
|
760
|
+ return false;
|
|
761
|
+ }
|
|
762
|
+
|
|
763
|
+ return $shop->hksy_count;
|
|
764
|
+ }
|
692
|
765
|
|
|
766
|
+ /**
|
|
767
|
+ * 扣减剩余数量 ZMH 2025-03-18
|
|
768
|
+ * @param $get
|
|
769
|
+ * @return bool|number
|
|
770
|
+ */
|
|
771
|
+ public static function subHKSYCount($post) {
|
|
772
|
+ $code = $post["code"] ?? '';
|
|
773
|
+ $count = $post["count"] ?? 0;
|
|
774
|
+ $remark = $post["remark"] ?? '';
|
|
775
|
+ if ($count <= 0 || empty($remark)) {
|
|
776
|
+ self::$errCode = 1;
|
|
777
|
+ self::$error = "参数错误";
|
|
778
|
+ return false;
|
|
779
|
+ }
|
|
780
|
+
|
|
781
|
+ $shop = self::getShopByCode($code);
|
|
782
|
+ if (empty($shop)) {
|
|
783
|
+ return false;
|
|
784
|
+ }
|
|
785
|
+
|
|
786
|
+ if ($shop->hksy_count < $count) {
|
|
787
|
+ self::$errCode = 5;
|
|
788
|
+ self::$error = "剩余数量不足";
|
|
789
|
+ return false;
|
|
790
|
+ }
|
|
791
|
+
|
|
792
|
+ Db::startTrans();
|
|
793
|
+ try {
|
|
794
|
+ //code...
|
|
795
|
+ $old_hksy_count = $shop->hksy_count;
|
|
796
|
+ $shop->hksy_count = $shop->hksy_count - $count;
|
|
797
|
+ $shop->save();
|
|
798
|
+ // 添加数量记录
|
|
799
|
+ $hk = new ShopHkLog();
|
|
800
|
+ $hk->shop_id = $shop['id'];
|
|
801
|
+ $hk->source_type = 101;
|
|
802
|
+ $hk->change_count = 0 - $count;
|
|
803
|
+ $hk->left_count = $shop->hksy_count;
|
|
804
|
+ $hk->remark = $remark;
|
|
805
|
+
|
|
806
|
+ $hk->save();
|
|
807
|
+
|
|
808
|
+ Db::commit();
|
|
809
|
+ } catch (\Throwable $th) {
|
|
810
|
+ //throw $th;
|
|
811
|
+ Db::rollback();
|
|
812
|
+ self::$errCode = 6;
|
|
813
|
+ self::$error = "扣除失败";
|
|
814
|
+ return false;
|
|
815
|
+ }
|
|
816
|
+
|
|
817
|
+ return $shop->hksy_count;
|
|
818
|
+ }
|
693
|
819
|
}
|