123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\common\api;
- use app\common\api\DictApi;
- use app\admin\model\Enterprise;
- use think\facade\Db;
- use app\common\model\IntegralRecord;
- use app\common\state\IntegralState;
- /**
- * Description of IntegralRecordApi
- *
- * @author sgq
- */
- class IntegralRecordApi {
- public static function getOne($id) {
- $result = IntegralRecord::where("id", "=", $id)->find();
- if ($result) {
- $result["items"] = $result->detail;
- }
- return $result;
- }
- public static function getList($params) {
- $where = [];
- $order = $params["order"] ?: "desc";
- $offset = $params["offset"] ?: 0;
- $limit = $params["limit"] ?: 10;
- if (session("user")["usertype"] == 2) {
- $where[] = ["enterprise_id", "=", session("user")["uid"]];
- }
- $count = IntegralRecord::where($where)->count();
- $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
- foreach ($list as $key => $item) {
- $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
- $tmp_items = [];
- foreach ($item["detail"] as $_item) {
- $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
- $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
- }
- $list[$key]["details"] = implode(",", $tmp_items);
- $list[$key]["type"] = session("user")["type"];
- }
- return ["total" => $count, "rows" => $list];
- }
- public static function checkIsEditable($id) {
- $info = self::getOne($id);
- if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
- return false;
- return true;
- }
- static public function chkIsOwner($id, $uid) {
- $info = self::getOne($id);
- if ($info["enterprise_id"] != $uid)
- return null;
- return $info;
- }
- }
|