CRMEB 常用代码

根据某列进行排序

$sorts = array_column($item['attrInfo'], 'sort');
array_multisort($sorts, SORT_ASC, $item['attrInfo']);

模拟延迟

sleep(5);

按钮权限

<Button v-auth="['product-product-rule-delete']" @click="del(null,'批量删除规格')">批量删除</Button>

记录日志,序列化

use think\facade\Log;

$d = $this->withSearchSelect(array_keys($where), $where);

Log::record(serialize($where),'error');
Log::record($this->getModel()::getLastSql(),'error');


$res = $this->getModel()::where($where)->delete();
Log::record($this->getModel()::getLastSql(),'error');

事务保存

$this->transaction(function () use ($id, $data $storeProductCateServices) {});   

查找一个元素

var item = arr_allInputList.find(c => c.value == value);

下来清空 clearable

<Select v-model="artFrom.is_show" placeholder="请选择" clearable @on-change="userSearchs">
    <Option value="1">显示</Option>
    <Option value="0">隐藏</Option>
</Select>

数组相加 = 数组合并

        $sumNumber = $this->dao->search($where + $whereData)->field([
            'sum(total_num) as sum_total_num'
        ])->find();

读取配置
$reason = sys_config('stor_reason') ?: [];// 退款理由

关联查询

model层

    /**
     * 门店一对一关联
     * @return \think\model\relation\HasOne
     */
    public function store()
    {
        // store_name 相当于 别名
        return $this->hasOne(SystemStore::class, 'id', 'store_id')->field(['id', 'name'])->bind([
            'store_name' => 'name'
        ]);
    }

dal层

        return $this->search($where)
            ->with('store')
            ->when($page && $limit, function ($query) use ($page, $limit) {
                $query->page($page, $limit);
            })
            ->order('id DESC')
            ->field('id,store_id')// 这里必须包含外键
            ->select()->toArray();

自定义列

{
    title: '#',
    align: 'center',
    width: 50,
    render: (h, params) => {
        return h('div', {
            domProps: {
                innerHTML: "" + (params.index+1)
            }
        });
    }
}
{
    title: '商品名称',
    minWidth: 120,
    render: (h, params) => {
        return h('div', {
            domProps: {
                innerHTML: params.row.productInfo.store_name
            }
        });
    }
}

数组转字符串
implode() 函数返回一个由数组元素组合成的字符串。

$data['day_time'] = implode(' - ', $data['day_time']);

后端校验

validate(\app\adminapi\validate\merchant\SystemStoreValidate::class)->scene('save')->check($data);
posted @ 2022-01-12 10:05  古兴越  阅读(319)  评论(0编辑  收藏  举报