| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | <?phpnamespace App\Modules\OfficialAccount\Models;use Illuminate\Database\Eloquent\Model;use DB;class CustomSendMsgs extends Model{    protected $tables = 'custom_send_msgs';    protected $fillable = ['task_id', 'user_num', 'appid', 'name', 'send_time', 'content', 'redirect_url', 'status', 'distribution_channel_id', 'subscribe_time', 'sex', 'balance', 'order_type', 'category_id', 'del_flag', 'is_full_send', 'trusteeship', 'batch_no', 'is_show_list', 'description', 'book_name', 'chapter_name', 'is_activity','subscribe_time_attach'];    /**     * 判断1小时内是否有相同的客服消息插入过     */    static function isSendCustomerAtSameTime($distribution_channel_id, $appid, $send_time)    {        return self::where(['distribution_channel_id' => $distribution_channel_id, 'appid' => $appid, 'del_flag' => 0])->where('status', '!=', '4')->where('send_time', '<', date('Y-m-d H:i:s', strtotime($send_time) + 3600))->where('send_time', '>', date('Y-m-d H:i:s', strtotime($send_time) - 3600))->first();    }    /**     * 判断1小时内是否有相同的客服消息插入过     */    static function isSendCustomerAtSameTimeAndSex($distribution_channel_id, $appid, $send_time, $sex)    {        return self::where(['distribution_channel_id' => $distribution_channel_id, 'appid' => $appid, 'sex' => $sex, 'del_flag' => 0])->where('status', '!=', '4')->where('send_time', '<', date('Y-m-d H:i:s', strtotime($send_time) + 3600))->where('send_time', '>', date('Y-m-d H:i:s', strtotime($send_time) - 3600))->first();    }    /**     * 根据渠道号获取客服消息     */    static function customSendMsgsByChannelId($distribution_channel_id)    {        return self::where('distribution_channel_id', isset($distribution_channel_id) ? $distribution_channel_id : '')->where('del_flag', 0)->where('is_show_list', 1)->orderBy('id', 'desc')->paginate();    }    /**     * 根据渠道号和自定义标识获取客服消息     */    static function customSendMsgsByChannelIdAndTrusteeship($distribution_channel_id, $trusteeship = 1)    {        return self::where('distribution_channel_id', $distribution_channel_id)->where('trusteeship', $trusteeship)->where('del_flag', 0)->orderBy('id', 'desc')->paginate();    }    /**     * 根据自定义标识获取所有批次客服消息     */    static function customSendMsgsByTrusteeship($trusteeship = 1)    {        return self::where('trusteeship', $trusteeship)->where('del_flag', 0)->select('custom_send_msgs.*', 'custom_send_msgs.created_at as create_time')->orderBy('batch_no', 'desc')->orderBy('id', 'desc')->paginate();    }    /**     * 根据批次号获取客服消息     */    static function customSendMsgsByTrusteeshipAndBacthNo($trusteeship = 1, $batch_no)    {        return self::where('trusteeship', $trusteeship)->where('batch_no', $batch_no)->where('del_flag', 0)->orderBy('id', 'desc')->get();    }    /**     * 根据task_id获取客服消息     */    static function customSendMsgsByTaskid($task_id)    {        return self::where('task_id', isset($task_id) ? $task_id : '')->first();    }    /**     * 根据id获取客服消息     */    static function customSendMsgsById($id)    {        return self::where('id', isset($id) ? $id : '')->first();    }    /**     * 根据状态获取客服消息     */    static function customSendMsgsByStatusStandBy($status)    {        return self::where(['status' => $status, 'del_flag' => 0])->get();    }    /**     * 根据分页获取客服消息     */    static function customSendMsgsPaginate($start_time, $end_time, $is_all = false)    {        $search_obj = self::select('custom_send_msgs.distribution_channel_id as site_id',            'custom_send_msgs.name as task_name',            DB::raw('date(custom_send_msgs.created_at) as created_date'),            'custom_send_msgs.send_time',            'custom_send_msgs.user_num as suc_send_num',            DB::raw('"" as template_name'),            DB::raw('"" as tag'),            DB::raw('(select group_concat(nickname) from official_accounts where distribution_channel_id=custom_send_msgs.distribution_channel_id group by distribution_channel_id)  as  official_account_name')//official_account_name        )            ->where(['del_flag' => 0, 'status' => 3])            ->where('custom_send_msgs.created_at', '>=', $start_time)            ->where('custom_send_msgs.created_at', '<', $end_time)            ->orderBy('id', 'desc');        if ($is_all) {            return $search_obj->get();        } else {            return $search_obj->paginate();        }    }    static function searchCustomSendMsgs($param, $is_all = false)    {        $res = self::where('distribution_channel_id', $param['distribution_channel_id'])            ->select('*')            ->where('del_flag', 0)            ->where('is_show_list', 1);        if (isset($param['start_time']) && $param['start_time']) {            $res->where('custom_send_msgs.created_at', '>=', $param['start_time']);        }        if (isset($param['end_time']) && $param['end_time']) {            $res->where('custom_send_msgs.created_at', '<=', $param['end_time']);        }        if (isset($param['book_name']) && $param['book_name']) {            $res->where('custom_send_msgs.book_name', 'like', '%' . $param['book_name'] . '%');        }        if (isset($param['task_name']) && $param['task_name']) {            $res->where('custom_send_msgs.name', 'like', '%' . $param['task_name'] . '%');        }        if ($is_all) {            $custom_send_msgs = $res->orderBy('id', 'desc')->get();        } else {            $custom_send_msgs = $res->orderBy('id', 'desc')->paginate();        }        return $custom_send_msgs;    }}
 |